We have a multitenant application that uses Azure DocumentDB as our NoSQL document oriented database.
For multitenancy, we read this question and this blog post. Because right now our number of users do not meet the need to use different databases and/or documentCollections
, and more importantly, for cost savings we implemented multitenancy with a "Where" clause on a TenantId field with one documentCollection
.
Similarly, when it comes to storing "documents" or "objects" with complete different natures (say for example Book
and Car
) we are questioning ourselves on the fact to use one documentCollection
.
At first, it looks more reasonable to create two different documentCollection
for Book
and Car
. However, creating a documentCollection
costs 25$ minimum. We do not want to pay +25$ everytime we need to add a new feature even if it is to store a low amount of data (e.g. our app stores a lot of Books
but few Cars
...).
Is it a good design to put Book and Car in the same documentCollection
? And keep a reference to the type of the document in a shared member (e.g. string Type ="Book" or string Type = "Car"
).
Knowing that we have already implemented the Multitenancy with a Where "clause", to query all Cars in our App for a given tenant, our queries would all contain Where TenantId ="XXXX" AND Type = "Car"
.
I have seen that DocumentDB supports now the Partitioned Collection. Could this be a good usage of the partitions or, on the contrary, they should be kept to achieve better scalability and are not adapted to segregate different document types whose object quantities may not be similar?
Databases are sets of collections. Collections store records, which are referred to as documents. Collections are the equivalent of tables in RDBMS, and documents can be thought of as rows in a table. The difference is that you don't define what columns (or rather attributes) there will be in advance.
Upserts a Document as an asychronous operation in the Azure Cosmos DB service. UpsertDocumentAsync(Uri, Object, RequestOptions, Boolean, CancellationToken) Upserts a document as an asynchronous operation in the Azure Cosmos DB service.
Azure Cosmos DB is the next big leap in globally distributed, at scale, cloud databases. As a DocumentDB customer, you now have access to the new breakthrough system and capabilities offered by Azure Cosmos DB.
Yes, it is "good design" to use type="Book"
. You can also do isBook=true
, which I believe is slightly more efficient and enables inheritance and mixin behavior.
Partitioned Collections are actually a way to put more stuff into a single larger entity rather than the other way around. The idea is to allow scaling of both throughput (RUs) and space without the burden of managing multiple Collections yourself. You "could" make your partition key be your type
field, but I would not recommend it. Partition keys should enable roughly even spread among partitions... among other criteria.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With