This behavior doesn't seem to be specific to the C# driver. I can get
the same result using just the mongo shell:
> db.test.remove()
> db.test.ensureIndex(
... {"Person.Name" : 1, "Person.Surname" : 1, "Person.Age" : 1,
"Properties.ProperyName" : 1},
... { unique : true }
... )
> db.test.insert({
... Person : { Name : "John", Surname : "Doe", Age : 20 },
... Properties : [
... { PropertyName : "company", PropertyValue : "abc" },
... { PropertyName : "address", PropertyValue : "xyz" }
... ]})
> db.test.insert({
... Person : { Name : "John", Surname : "Doe", Age : 20 },
... Properties : [
... { PropertyName : "company", PropertyValue : "def" },
... { PropertyName : "address", PropertyValue : "ghi" }
... ]})
E11000 duplicate key error index: test.test.
$Person.Name_1_Person.Surname_1_Person.Age_1_Properties.ProperyName_1
dup k
ey: { : "John", : "Doe", : 20.0, : null }
>
It must have something to do with how arrays are indexed.