Reputation: 4058
My document is:
{
"firstName" : "My first name",
"lastName": "My lastName",
}
I have indexed fields fristName
and lastName
with unique sparse index. Which means that I will always have unique firstName
and lastName
in my database.
But it can have null values(i.e field is missing when inserting it to the database) for fields firstName
and lastName
.
This is working fine as expected in MongoDB v3.4. But when I am trying to insert using the same code in cosmosdb I am getting error
multiple write errors: [{write errors: [{E11000 duplicate key error collection: user Failed _id or unique key constraint}]}, {<nil>}]
Does cosmosdb support unique sparse index?
I found this link which say it do not support uniue sparse index
.
And this link which says sparse index
is supported by default.
Upvotes: 3
Views: 782
Reputation: 1027
There is a difference between unique sparse indexes and defining a collection unique key based upon a sparse document property. So, the portion of your post with regard to it being not supported:
I found this link which say it do not support uniue sparse index.
Is really talking about using a sparse document property as a partition key is not supported:
Sparse unique keys are not supported. If some unique path values are missing, they're treated as null values, which take part in the uniqueness constraint. For this reason, there can be only a single item with a null value to satisfy this constraint.
Please take a look at the following Stack Overflow post.
Upvotes: 2