Randar Puust
Randar Puust

Reputation: 373

MongoDB - Different collection per tenant

We have a multi-tenant application and plan to store a significant amount of data in MongoDB. For now, the plan is to have the same document schema across all tenants. I’m new to Mongo, but I had a thought that it might make sense to store each tenant in it’s own sub-collection. For example database.collection.sub-collection would be:

Here is what I think the pros and cons will be:

Pros:

Cons:

Should I even consider this? Should I just stick with a single collection for all my tenants?

Upvotes: 1

Views: 4529

Answers (1)

Randar Puust
Randar Puust

Reputation: 373

Not sure I missed it the first time, but this has been discussed at What is the recommended approach towards multi-tenant databases in MongoDB?.

Based on some thinking time and that post, going with a single database, with a tenant key added to each document. Not a collection per tenant.

Upvotes: 3

Related Questions