2

I am facing issue with CosmosDB unique key constraint. After setting up the unique key, I am able to insert duplicate documents withing same partition key. Please help me to understand if I am doing anything wrong.

Created a container with the unique key as "/name" and partition key as "/partition"

I was able to create duplicate name under same partition key using azure portal data explorer tool

Doc 1

{
"id": "1",
"partition": "p1",
"name": "Balaji",
"age": 20,
"_rid": "Y48OAI3aptUBAAAAAAAAAA==",
"_self": "dbs/Y48OAA==/colls/Y48OAI3aptU=/docs/Y48OAI3aptUBAAAAAAAAAA==/",
"_etag": "\"8e016bfd-0000-0700-0000-5e96d8a50000\"",
"_attachments": "attachments/",
"_ts": 1586944165
}

Doc 2

{
"id": "2",
"partition": "p1",
"name": "Balaji",
"age": 20,
"_rid": "Y48OAI3aptUCAAAAAAAAAA==",
"_self": "dbs/Y48OAA==/colls/Y48OAI3aptU=/docs/Y48OAI3aptUCAAAAAAAAAA==/",
"_etag": "\"8f017400-0000-0700-0000-5e96d8d60000\"",
"_attachments": "attachments/",
"_ts": 1586944214
}

Advance Thanks !!

Balaji A
  • 43
  • 6
  • 1
    I just tried this and I was not able to save the data (got the constraint violation error). Please check if you have set the unique key policy correctly. – Gaurav Mantri Apr 15 '20 at 11:19
  • Thanks @GauravMantri, apparently looks like the issue with Azure portal Data explorer UI issue. When creating a container from Azure portal, its not considering the provided unique key information. – Balaji A Apr 15 '20 at 13:03

1 Answers1

3

Drop the container and recreate it with unique key. You can't see unique key information in anywhere in UI that makes debugging very difficult. Also, check out my blog about unique key for more information if you like. https://h-savran.blogspot.com/2019/08/how-unique-is-azure-cosmos-db-unique.html

Hasan Savran
  • 367
  • 2
  • 5