4
votes

Looking at how to set up DocumentDb with a partition key, if I have a multi-tenant application, where most documents have a tenantId, it seems reasonable to create the collection with a partition key of /tenantId/.

What happens to documents that don't have a tenantId property? Will they just get added without one, or will Cosmos DB create those objects/documents with some kind of system (hard-coded) tenantId, so they are stored together?

1

1 Answers

6
votes

These documents are automatically assigned the "undefined" value for partition key (similar to JavaScript's undefined). This is treated like any other value, and all documents with missing keys are stored within the same partition. If you have a large number of these, then you would have trouble scaling as all writes within missing keys would get assigned to the same partition.

It's generally a good idea to avoid this, or fix this later by deleting/reinserting (if this lack of partition key is due to some asynchronous nature of not knowing the partition key at creation time).