Reputation: 3030
I'm working with a Cosmos DB collection partitioned by account ID, and I need to prevent the addition of duplicate serial numbers.
So, if Johnny with account ID 123 tries to add an item with serial number A562, Bill with an account ID of 987 can't add an item with serial number A562. However, they may not be in the same partition.
Is there a way to ensure uniqueness across partitions without doing an expensive search through every partition first?
Upvotes: 2
Views: 1038
Reputation: 23782
Based on the official doc Unique keys in Azure Cosmos DB : By creating a unique key policy when a container is created, you ensure the uniqueness of one or more values per partition key.
So the unique key can not ensure uniqueness across partitions so far.
I suggest you use sql SELECT VALUE COUNT(1) FROM c where c.serialNumber = '***'
to check if the result is larger than 2
.
Hope it helps you.
Upvotes: 4