I have an existing Azure Cosmos DB that uses /id for the partition key. We need to do a bulk delete but we can’t do that because the partition key is not the same for all the records. Is there a way to update the partition key and partition key value of existing azure cosmos DB container?
2
Answers
To update any property in a document you’d need the
id
, if you know theid
of your documents then might as well just use that for the Bulk Delete.You can use the SDK in Bulk Mode, get the list of
ids
and perform concurrentDeleteItemAsync
operations, because you know theid
and your current partition key is/id
then you know the Partition Key value to use too.Simple answer – No. It is not possible to change the partition key attribute of an existing container (collection). Furthermore it is not possible to change the value of a partition key of existing documents inside a container.
To change the partition key value of documents, you will need to create new documents with new partition key value and delete existing ones.
To change the partition key attribute of an existing container, you will need to create a new container and migrate the data from old container to new container.