An Azure NoSQL database service for app development.
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):
- Open the Azure Cosmos DB account in the Azure portal and go to Data Explorer.
- Select the container whose partition key needs to be changed.
- Go to Scale & Settings → Partition Keys tab.
- Select Change to start the partition key change process.
- 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.
- The portal will start an intra-account container copy job that copies data from the source container to the destination container offline.
- Stop all updates to the source container for the entire duration of the copy to maintain data integrity.
- 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:
- Changing the partition key in Azure Cosmos DB (preview)
- Partitioning and horizontal scaling in Azure Cosmos DB
- Replace a Collection
- DocumentCollection Class
- Using the Azure CosmosDB NoSQL Vector Store connector (Preview) (programming-language-csharp)
- Using the Azure CosmosDB NoSQL Vector Store connector (Preview) (programming-language-python)
- ChangeFeedOptions.PartitionKey Property