Search⌘ K
AI Features

Overview of Constraints

Explore how to implement unique key constraints within Azure Cosmos DB containers to ensure data consistency at the partition level. Understand the limitations, container creation options, and practical steps using Azure portal, CLI, and SDK to manage these constraints.

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 ...