Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Azure Cosmos DB, can we change partition key later on once we decided at the beginning

I am new to Cosmos DB and I noticed that we can set the partition key based on needs to scale effectively through code like this:

DocumentCollection myCollection = new DocumentCollection();
myCollection.Id = "coll";
myCollection.PartitionKey.Paths.Add("/deviceId");

Question is can we change the partition key later on after we created the collection and specified the partition key? As I may find out that the choice of partition key is not proper later.

like image 447
Mike Avatar asked Jul 18 '17 18:07

Mike


People also ask

Can I update partition key in Cosmos DB?

We can't change the partition key for this container anymore. You can only set it when you create a new container. 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.

Can we have multiple partition keys in Cosmos DB?

In this lab, you will create multiple Azure Cosmos DB containers. Some of the containers will be unlimited and configured with a partition key, while others will be fixed-sized. You will then use the SQL API and Java Async SDK to query specific containers using a single partition key or across multiple partition keys.

How do I change the unique key on a Cosmos database?

You can't update an existing container to use a different unique key. In other words, after a container is created with a unique key policy, the policy can't be changed. To set a unique key for an existing container, create a new container with the unique key constraint.


1 Answers

Changing the partition key is not supported (see e.g. https://docs.microsoft.com/en-us/rest/api/cosmos-db/replace-a-collection). You would need to create a new collection.

like image 197
quervernetzt Avatar answered Sep 25 '22 17:09

quervernetzt