Azure Cosmo DB partitioning

While preparing for AZ-303 exam, I was using couple of resources:

I was stuck answering the questions about inserting items in the CosmoDB, using SQL API. So in the end, I decided to use the real Cosmo DB instance and did exactly the same, what was asked in the questions. The outcome is that the answers in both mentioned resources were wrong.

From Azure Cosmo DB resource model :

  • id for an item is a “unique name in a logical partition”, which could be defined by System or User. So if you do not defined it, it will be AUTO-GENERATED.
  • Uniqueness of the id property is only enforced within each logical partition. Multiple documents can have the same idproperty with different partition key value”. If there is already an item in a particular logical partition, which is defined by partition key, with the same id, you won’t be able to add a new item with the same id and partition key.

For example, you have a container with a partition key /id and there is an item

{

“id”: “1”,

“name”:"user1"

}

You won’t be able to add

{

“id”: “1”,

“name”: “user2”

}

The error would be “Entity with the specified id already exists in the system”.

So the best advice for any exam preparation is to try to use as many topics as possible in practice.

--

--