I am working on an enterprise level multi tenancy system and we are discussing how to partition our MongoDB and I'm reading up on how to do this but I have a few questions if there is an expert here that can help me. Just to underline: I have read up on this and tried to search for info, but it fails to answer my question (or my google-fu fails me completely).
Question 1: One customer per collection.
This scenario is something that people talk about avoiding and I'm not really satisfied with the answer way. I understand that there is a namespace limit and there is a problem if you have more than 100 collections, but what if you build around that?
My idea is to limit the maximum of collections in a database to X (50? 80? 30? some cool number) and to use several instances of the database but not one per customer. This is due to economy, I want to press the cost per tenant and thus putting several tenants in one database and placing each tenant in a collection to create a good scaling of the collections. As far as I understand when I read the documentation about Mongo DB my scenario above would be OK as long as I keep a watchful eye on how many collections I have in each database. This will give me a good spread of info over the different collections, thus utilizing MongoDBs scaling possibilities while still keeping the cost resonable. The connectionstring to different databases would not be a huge issue, I can handle that simply enough.
I would find the above scenario easier than keeping the customers seperated with customer_id and spreading the info into different collection based on something else.
Is my reasoning still incorrect? If yes - why? Where is my logic failing me?
Question 2: (This question is only valid if the answer to question 1 is "no no, you are right" :) ) If I now use the above scenario and I have multiple customers that are a chain of stores for instance. Let's say IKEA (they have a lot of stores) and you have a general manager some place that needs information from all of the IKEA tenants I would need to go into several collections to find the overall statistic info, is this a problem? I already thought about placing certain customers in one specific database for them (like IKEA or other chains) meaning that if they are less than 100 stores then I "only" need to view one database, but I need to fetch information from several different collections, is this a problem?
I know there are several references to similar questions, like:
What is the recommended approach towards multi-tenant databases in MongoDB?
https://web.archive.org/web/20140812091703/http://support.mongohq.com/use-cases/multi-tenant.html
but I feel that they lack the answer to this form of question.
I hope you understand the difference in my question. Thanks a lot!