I have a cosmos db container with below fields (id,name,Category,Type). I am new to cosmos db and playing around with it. I will be doing search using ID, Name. What will be the better way to create a partition key?
Asked
Active
Viewed 59 times
1 Answers
0
While deciding partition key you need to choose a property/attribute that will not change. Cosmos db does not allow you to change it.
As you mentioned you mostly will be searching around id and name, I would suggest you to keep your partition key on Id as name could change. You can also put Category as a partition key and all similar objects will be grouped together in physical/logical partitions based on it. You can read through this article which has very apt description on your requirements.
Also, you can create a synthetic key based on combination of both these id and name properties (Refer), but this would not make much sense in this case.

AnuragSharma-MSFT
- 622
- 4
- 6