Saving different types of documents in one DocumentDb collection

We have a multi-tasking application that uses Azure DocumentDB as our zero-SQL database.

For multithreading, we read this question and this blog post . Since now the number of users does not meet the needs of using different databases and / or documentCollections , and, more importantly, to save money, we implemented multitasking with the Where clause in the TenantId field with one documentCollection .

Similarly, when it comes to storing “documents” or “objects” with completely different natures (for example, Book and Car ), we question the fact of using one documentCollection .

First, it makes more sense to create two different documentCollection for Book and Car . However, creating a documentCollection costs $ 25 a minimum. We don’t want to pay + $ 25 every time we need to add a new function, even if it is designed to store a small amount of data (for example, our application stores a lot of Books , but few Cars ...).

Is it a good design to put a book and a car in the same documentCollection ? And save the link to the document type in the shared element (for example, string Type ="Book" or string Type = "Car" ).

Knowing that we have already implemented Multitenancy with a Where clause to request all the cars in our application for this tenant, our requests will contain Where TenantId ="XXXX" AND Type = "Car" .

I saw that DocumentDB now supports the Partitioned Collection . Could this be a good use of sections or, conversely, should they be supported to achieve better scalability and not adapted to separate different types of documents whose objects may not be similar?

+7
azure azure-cosmosdb
source share
1 answer

Yes, this is a "good design" to use type="Book" . You can also do isBook=true , which, in my opinion, is a bit more efficient and allows mixin inheritance and behavior.

Shared collections are actually a way to put more material into one big entity, and not vice versa. The idea is to allow scalability of both bandwidth (RU) and space without the burden of managing multiple collections on your own. You can make your section key your type field, but I would not recommend it. Partition classes should include approximately equal distribution among partitions ... among other criteria.

+8
source share

All Articles