How to implement multitenant MongoDB
I am looking to implement a MongoDB system that ha开发者_开发知识库s 3 major collections (People, Surveys, Responses) and a few minor collections (lookups etc). However, the system will be multi-tenant, so I will need a set of collections for each tenant. My question is should I have separate DBs for each tenant, or should I have a single db. With a single db, should I name my collections as follows: tenantname_people, tenantname_surveys etc, or is there a better way to structure/name my collections? I like the single db approach, because then I can have a tenant collection, with details of each tenant and their users etc, which will be helpful for support. I will have quite a few indexes, and I have one eye on the 24k limit on namespaces. 24k seems high, but these things can haunt you.
Any helpful comments would be greatly appreciated. Thanks.
I'd recommend having separate DB per tenant. This can help you with sharding as well. You can increase the namespace limit if you want to using the --nssize argument.
definitely a separate DB is the appropiate way, so you can easily apply replication and make redundant versions of a tenant. a single DB will bite you when you want to scale out the service
what you need to do is have a tenant ID and a single user db which is a management db and you can have there the information for users and tenants.
精彩评论