Is it possible to set a unique key restraint on an array in cosmos db

Michael Comiskey 20 Reputation points
2023-01-29T15:43:11.9566667+00:00

From the all the documents I’ve read it’s possible to set a unique key restrain on a single property in a document but is it possible to set it to an array..

Thanks Mike

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,454 questions
0 comments No comments
{count} votes

Accepted answer
  1. Umang Middha 550 Reputation points
    2023-01-29T16:21:24.3333333+00:00

    Hello Michael,

    Hope you are doing well today!

    No, it is not possible to set a unique key constraint on an array in Cosmos DB in Azure. In Cosmos DB, unique key constraints can only be set on individual fields and not arrays. If you need to enforce uniqueness for array values, you can add a field to store a hash of the array and set a unique key constraint on the hash field. I hope this answers your query.

    Regards,
    Umang Middha

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful