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
Japanwill 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?
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;