Change Partition Key for Azure Cosmos DB Container | AZ-303 Exam Question | Microsoft Azure

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 Change Feed Processor and Bulk Executor Library, in Azure Cosmos DB 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/

The correct answer is A. Delete Container1.

Explanation: In Azure Cosmos DB, the partition key determines how data is distributed across physical partitions, and changing the partition key for a container is a non-trivial task. It requires migrating data from the old partition key to the new partition key, which can be time-consuming and resource-intensive. Therefore, the best approach is to delete the container and recreate it with the new partition key.

Here are some additional details about the other answer options:

B. Create a new Azure Cosmos DB account: This is not necessary, as changing the partition key for a container does not require creating a new account. Moreover, creating a new account would require migrating all the existing data and applications to the new account, which can be complex and risky.

C. Implement the Azure Cosmos DB .NET SDK: The .NET SDK is a programming library that allows you to interact with Azure Cosmos DB programmatically. While the SDK can be helpful in performing various tasks, such as querying data, it does not provide a direct way to change the partition key for a container.

D. Regenerate the keys for Account1: Regenerating the keys for an Azure Cosmos DB account is unrelated to changing the partition key for a container. Regenerating keys simply creates a new set of access keys that can be used to authenticate requests to the account.