Changing the partition key for Container1 in Azure Cosmos DB

Change Partition Key for Azure Cosmos DB Container

Question

You have an Azure Cosmos DB account named Account1. Account1 includes a database named DB1 that contains a container named Container1. The partition key for Container1 is set to /city.

You plan to change the partition key for Container1.

What should you do first?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

B

The good news is that there are two features, the Change Feed Processor and Bulk Executor Library, in Azure Cosmos DB that can be leveraged to achieve a live migration of your data from one container to another. This allows you to re-distribute your data to match the desired new partition key scheme, and make the relevant application changes afterwards, thus achieving the effect of "updating your partition key".

Incorrect Answers:

A: It is not possible to "update" your partition key in an existing container.

https://devblogs.microsoft.com/cosmosdb/how-to-change-your-partition-key/

If you plan to change the partition key for a container in an Azure Cosmos DB account, you should first consider the impact of this change on your existing data and application. Changing the partition key of a container can result in data redistribution, which can impact the performance of your application. Additionally, any queries that rely on the previous partition key may need to be modified to reflect the new partition key.

Once you have considered the impact of changing the partition key, the next step is to determine the new partition key that you want to use. The new partition key should be chosen carefully based on the access patterns of your application, as well as the expected growth of your data.

After you have determined the new partition key, you can follow these steps to change the partition key for a container in an Azure Cosmos DB account:

  1. Create a new container in the same database with the new partition key.
  2. Migrate the data from the old container to the new container using tools such as Azure Data Factory or the Azure Cosmos DB Data Migration tool.
  3. Update your application to use the new container and partition key.
  4. Monitor the performance of your application to ensure that the new partition key is providing the expected benefits.

Therefore, the correct answer to the given question is option B: Create a new container in DB1.