When we deploy a Sharded Cluster, without having a sharded collection in our database, what is the default behaviour of MongoDB? How does MongoDB, distributes the data across the shards?

  • 1
    This is covered in the documentation on Sharded and Non-Sharded Collections. "A database can have a mixture of sharded and unsharded collections. Sharded collections are partitioned and distributed across the shards in the cluster. Unsharded collections are stored on a primary shard. Each database has its own primary shard." – Stennie May 30 '18 at 4:56

The answer is for existing data NO. But when you create new DB, different databases have different primary shard (system use round robin selection criteria), but as long as the collection (at that DB) is not sharded, all data stays at that primary shard.

  • 1
    Each database is associated with a primary shard, so unsharded collections in the same database will be on the same primary shard. – Stennie May 30 '18 at 5:06
  • 1
    Yes. You are right, my typo.. When you create new database to cluster, system selects (round robin style) primary shard for DB.. I fixed my answer. – JJussi May 31 '18 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.