Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Azure Cosmos db partition key to re-distribute existing data (document db)

Currently, my data is in azure cosmos db (DocumentDB) with wrong or un-optimized partition key. Now I want to update partition key and re distribute my data but not able to figure it out. How can I do it?

like image 444
Nikunj Aggarwal Avatar asked Aug 21 '17 09:08

Nikunj Aggarwal


People also ask

Can I update partition key in Cosmos DB?

Selecting your partition key is a simple but important design choice in Azure Cosmos DB. Once you select your partition key, it is not possible to change it in-place. If you need to change your partition key, you should move your data to a new container with your new desired partition key.

How do I update the partition key column in Cosmos DB?

If you do need to change a partition key, you need to create a new container and migrate your data to that one. A partition key consists of a path. This can be something like /firstname or /name/first, or a nested property, as long as it is a JSON property from the documents in the container.

Can partition key be changed?

Note that you can't change the partition key of a container. If you do need to change it, you need to migrate the container data to a new container with the correct key.


1 Answers

Now I want to update partition key and re distribute my data but not able to figure it out how can I do it.

Currently it is not possible to update the partition key attribute in a collection or change partition key value in a document.

If you want to change the partition key attribute, you would need to delete that collection and create a new one with correct partition key attribute.

Similarly, if you wish to update the partition key value in a document you must first delete the document and create a new document with correct partition key value.

like image 83
Gaurav Mantri Avatar answered Sep 22 '22 07:09

Gaurav Mantri