15
votes

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.

1
I believe you cannot. In my experience I ended up creating a new collection when wanting to change the partition key. You may find more information here: docs.microsoft.com/en-us/azure/cosmos-db/… - brudert

1 Answers

7
votes

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.