Search code examples
mongodbsharding

MongoDB - Max number of collections


In MongoDB the max number of namespaces is about 24.000

I would like to know if this max number can increase with sharding. ie if I have two shards, can it be of 48.000 ?

Thank you


Solution

  • The approximately 24,000 max number of namespaces is only true for the MMAPv1 storage engine.

    The WiredTiger storage engine is not subject to this limitation. See the Number of namespaces section in the MongoDB limits and thresholds page. WiredTiger has been the default storage engine since MongoDB 3.2.

    To answer the 2nd question, that limitation is per-mongod, and that is due to the limitation of the namespace file that MMAPv1 uses.

    If you create two shards, you can double this limitation if you keep the two shards entirely separate, e.g. keep certain database in one shard, keep others in the other shard, and not enable sharding on any database.

    Basically you're creating two entirely separate deployments that happen to be viewed as a single thing, and this kind of defeats the original purpose of sharding (i.e. increasing throughput for a very busy collection/database). It might be operationally easier to just create two deployments instead.