Looking at a CosmosDb NoSQL instance, I need to introduce UniqueKeys into my Container, based on two field from my items: A and B. The docs mention I should create a compound key, using { A, B }
in the unique key constraint.
But I was thinking about another approach. What if, on each item, I create a field UniqueKey = Concat(A,B)
, and set this one field as the unique key? The upside is that if I need to include a field C in the unique key constraint, I don’t have to re-create a container and lose all data, I just update my code to construct the new UniqueKey before items are inserted into the database.
Does this approach have any downsides compared with the one suggested by the docs? I’m particularly interested in performance downsides.
Tries do search docs, found nothing:
https://learn.microsoft.com/en-us/azure/cosmos-db/unique-keys
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-define-unique-keys?tabs=dotnetv2
David Beyda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.