3

I am looking to implement a MongoDB system that has 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.

1

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

--nssize docs are here (mongodb.org/display/DOCS/Using+a+Large+Number+of+Collections). Important to note that the 24k limit is per db. If you have a separate DB per tenant then you'll sidestep this requirement.
-1

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.

2 Comments

Not definitely — each database gets pre-allocated file space and your databases will grow very quickly (see here: mongodb.org/display/DOCS/Excessive+Disk+Space). Using server-grade hardware with replication this cost quickly adds up. Personally I think it's better to go for the single DB and keep an eye on the namespace limits (serverdensity.com can do this for you).
consider using Collections (mongodb.org/display/DOCS/Collections) instead of completely separate databases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.