I'm working with a system that requires multiple databases for multiple organisation. A monolithic node Js server connects to these databases. The challenge is I may have 5000 organisation.
I wanted to know is there any limit for creating databases in a single mongodb cluster ?
If so what is the maximum number of databases that are allowed ?
If the cluster can handle as many databases as I add, is there any issue for scalability with this design ?
Assuming I have 5000 databases and 50 collections on each database, can a cluster handle this setup efficiently or is it even possible?
I went through some of the mongodb docs and tried to find limitations for different features of mongodb unfortunately I didn't find enough information on this topic .
CodePudding user response:
Mongo has no limits on the number of databases (or on the number of collections within a database).
Mongo up until 4.2 had substantial performance impacts when the number of namespaces (every collection and index) got too high (bug report). The cause of this was the need to have a global lock that scaled with the number of namespaces during checkpointing.
Even though this substantial performance bug has been addressed - I'd still be concerned about having a high number of databases in a single cluster.
The second thing that's worth considering is how busy those organisations will be - if you need to pay for a cluster of X power to support your 5000 databases, consider buying two clusters of X/2 power and splitting your DBs across them (or X/N - where a higher N is better). This gives you some resiliency too - if a single DB cluster is having issues, not all DBs are impacted.
Finally, I'd strongly consider using a single DB and handling your "organisations" at the application layer - this is how mongo was designed to operate and performs extremely well (if you setup the correct indexes). If you get to the point that you need multiple clusters for read/write performance, you can look into sharding - which works best in this single DB model (it really doesn't work meaningfully in multi-db models)