Yes, your approach of having the partition key combined with the unique key guarantees the uniqueness of an item within the scope of the container.'
Read more here
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi there,
I'm working on a REST API project that uses Java Spring Boot and Cosmos DB. I have multiple collections in this DB. This is the entity for one of the collections. I'd like to make one property unique, so no duplicate values can be inserted into this collection for the country
property. For example, only a unique value can be inserted. If we have already inserted Japan
, attempting to reinsert Japan
will result in an error.
Currently, I have set up both the partition key and unique key as country
. This achieves the goal of preventing duplicate values from being inserted. However, I'm not sure if it's a good practice to set up a collection like this. Any suggestions?
@Id
@GeneratedValue
private String id;
private String country; // I want to make it unique, No duplicate value can be inserted
private String description;
private String createdBy;
private String updatedBy;
Yes, your approach of having the partition key combined with the unique key guarantees the uniqueness of an item within the scope of the container.'
Read more here