2

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 .

1 Answer 1

4

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)

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

2 Comments

Thanks for your knowledge Zack. I was actually thinking about going with a single DB model. I had few concerns, if an organisation stops what should be the data migration strategy ? Should we also handle it with an application logic or any tool you can suggest ? Because then it looks like if we store these shared data in a single DB we can not use mongodb database tools ie mongodump for migration. Can you enlighten me on migration stretagy ? Appreciate your answer
It depends what you mean by "migration strategy" - mongodump isn't for migration (it's just barely suitable for backup/restore - as mongo states). Removing data when an org stops paying (if that's your criteria) should certainly be handled at the application layer

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.