Name the primary key of Container in Cosmbos DB Sql Api different than "id"

Viewed 302

I am working on Azure and I have created a database with Cosmos DB SQL API. After creating a container I see that the primary key is always named "id". Is there any way to create a container with PK with name different than "id"?

2 Answers

Every document has a unique id called id. This cannot be altered. If you don't set a value, it is assigned a GUID.

When using methods such as ReadDocument() (or equivalent, based on the SDK) for direct reads instead of queries, a document's id property must be specified.

Now, as far as partitioning goes, you can choose any property you want to use as the partition key.

And if you have additional domain-specific identifiers (maybe a part number), you can always store those in their own properties as well. In this example though, just remember that, while you can query for documents containing a specific part number, you can only do a direct-read via id. If direct reads will be the majority of your read operations, then it's worth considering the use of id to store such a value.

PK = primary key, by the way ;) It's the "main" key for the record, it is not private :)

And no, as far as I know you cannot change the primary key name. It is always "id". Specifically it must be in lowercase, "Id" is not accepted.

Related