1
votes

I created multiple collections through code without realising the importance of having a partition key. I have since read the only way to add a partition key and redistribute the data is by deleting the collection and recreating it.

I don't really want to have to do this as I have quite a-lot of data already and want to avoid the downtime. When I look the Scale & Settings menu in Azure for each of my collections is see this below.

enter image description here

Can someone explain this - I thought my partition key was null but looks like MS have given me one called _partitionKey? Can I not just add _partitionKey to my documents, run a script to update them all to the key I want to use (e.g country)?

1
i'm not sure i understand your question correctly, but you cannot change the partition key, if you want to update the documents with the partition key - you can do that, but you cannot change it (the name of the partition key). you can change the value on the document for the partition key as well - 4c74356b41
So _partitionKey is my partition key? None of my documents have this object in the json. If I add "_partitionKey": "France" to my document will this be used as a partition key? - Starchand
@Starchand yes, it should override _partitionKey set by Azure (which I presume is either just null or undefined). By default, if you don't define a PK then Azure will just allocate any documents to a null partition which of course isn't scalable. - James
@James ah, perfect! Thanks - Starchand
@Starchand yeah new documents will partition correctly, existing documents have already been physically stored and therefore would need to be removed & re-added to be moved into the correct physical partition. - James

1 Answers

2
votes

This is a new feature which allows non-partitioned collections (now called containers in the latest SDKs) to start using partitions with 0 downtime. The big caveat is that you need to be using the latest SDKs (which will be announced GA really soon (in fact most are already published, just waiting on doc publishing/etc.). Portal got the feature first since it's using the latest SDK under the covers already.