When doing multi-tenant applications using a RDMBS I use tenantId
columns in each table to indicate which tenant a row belongs to.
How would I do that in a DocumentDatabase? Let's take mongodb for instance. Is DBRef
the way to go? Or am I stuck in the relational thinking? Or would you use something other than a documentdb?
(I'm pretty new to nosql)开发者_如何学运维
If you have a need for Multitenancy under MongoDB you could use a different collection for each tenant. If the data is shared among all tenants I would instead keep a list of tenants for each entry like so:
doc: {
_id: doc1
... // your objects here
tenants: [ tenant1, tenant2, tenant17 ]
}
Then when I do a search or want a view of the database you should query with the relevant tenant:
db.mycoll.find({ someField : someValue, tenants : tenant2 });
精彩评论