I haven’t seen anything in the docs suggesting it, but does anyone know if there is an absolute limit to the total number of collections that a database can have?
I don’t know if there is any info about it in the official documentation. But, there are quite a few posts on the net with some information regarding. Here is one at StackOverflow: MongoDB - Max number of collections.
Welcome to the MongoDB Community forums!
I’m not aware of any coded limit to the number of collections. There is a practical limit based on the number of characters allowed in a namespace (details available here) but you should never reach anywhere near that many collections.
Though there may not be a hard limit, I’d advise against having more than about 150k active collections. It’s a general rule of thumb and not a hard rule. I also want to re-iterate that I’m talking about active collections (i.e. ones that receive read or write operations, statistic collection and monitoring commands, administrative commands, etc).
WiredTiger requires a file per collection and an additional file for every index. That means, at a minimum, each collection requires two files. Working with a collection in some way forces WiredTiger to open those files, which generates a file handle. I won’t get into the technical details (about dhandles, ulimits, etc) but it’s typical to start seeing operating system enforced filehandle limits around 64k collections. Overcoming that, more active collections means more active file handles. WiredTiger has to maintain those file handles, which becomes burdensome during checkpoints (which occurs every sixty seconds) and result in performance degradations.
I hope this helps clarify your question!