Overview of Constraints

Learn how to create unique key policies on a Cosmos DB container to improve consistency.

Constraints

We read that JSON documents are flexible multiple times and that applications must maintain consistency. However, there is something we can do at the container level—we can add unique key constraints. We can tell Cosmos DB that a value for a specific path, or a combination of multiple ones, is unique.

For example:

  • On a users container, we can set /email as unique.

  • On a games container, we can set the combination of /title and /year as unique.

Note: These limitations are applied only within a ...