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:
- mydb.archivedata.123456
- mydb.archivedata.123457
- mydb.archivedata.123458
Here is what I think the pros and cons will be:
Pros:
- It would be faster since the indexes would be smaller
- When looking through the data through something like Robo 3T, it would be easier to find documents.
- Easier to delete a tenant. Just delete their collection.
Cons:
- When doing something like support, it would be very hard to query across collections. e.g. Find me all the tenants that have this type of data. It sounds like this be a fairly complex if not impossible join to write.
- Whenever I want to make changes to the index, I would have to apply it to every collection
Should I even consider this? Should I just stick with a single collection for all my tenants?