Partitionkey for Cosmosdb

HimanshuSinha 19,637 Reputation points Microsoft Employee Moderator
2026-05-15T21:11:55.04+00:00

We need to change the partition key for our collection in cosmosdb , Just wanted to know how can we do that?

Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.


1 answer

Sort by: Newest
  1. AI answer

    2026-05-15T21:12:09.4733333+00:00

    Changing the partition key of an existing Azure Cosmos DB container cannot be done in place. The supported approach is to copy the data into a new container (or another existing container) that has the desired partition key.

    Using the Azure portal (NoSQL API, preview feature):

    1. Open the Azure Cosmos DB account in the Azure portal and go to Data Explorer.
    2. Select the container whose partition key needs to be changed.
    3. Go to Scale & SettingsPartition Keys tab.
    4. Select Change to start the partition key change process.
    5. Choose one of the following:
      • Create a new destination container with the new partition key definition, or
      • Select an existing destination container in the same database that already has the desired partition key.
    6. The portal will start an intra-account container copy job that copies data from the source container to the destination container offline.
    7. Stop all updates to the source container for the entire duration of the copy to maintain data integrity.
    8. After the copy completes, point the application to the new container and, if no longer needed, delete the old container.

    Key limitations for this feature:

    • Supported only for containers with < 1,000,000 RU/s provisioned throughput and < 4 TB of data. For larger containers, contact Microsoft support.
    • Not supported if the account has capabilities such as Disable local auth or Merge partition enabled.
    • Only available in specific supported regions.

    General design note:

    • Partition key values are immutable for individual items; an item’s partition key cannot be updated in place. To “move” an item between partitions, create a new item with the new partition key value and delete the old one. For changing the partition key definition for the entire container, use the container copy approach described above.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.