We are doing sharding process for 6 servers which includes 1 master process, 2 config process, 6 sharding processes.
We enabled the sharding by doing sh.enableSharding(database_name) and sh.shardCollection('mydb.collection_name', {_id: hashed}) It worked.
Now, if i add any other database/collection to the cluster, is there any way that, the database/collection get sharded automatically.

1 Answer 1


Answer is simple. NO! Every DB and collection in them, must be shard individually. Just because all collections are not created as equal and _id: hashed is not best solution to everything.

  • thanks @JJussi. So, what is the solution regarding _id? Jul 19, 2017 at 4:16
  • _id:hashed (or any sharding with _id) works only when (most of, not all necessary) your queries have _id field. Problem selecting sharding field is that is should be field what is included in most of queries. If sharding field is not included, you get scatter gather query (docs.mongodb.com/manual/core/distributed-queries) where query is sent to all shards and not only one. Yes, _id:hashed (or any 'key' with hashed) is "easy" solution where you get absolutely equal/even distribution of data. Hopefully this ( mongodb.com/blog/post/on-selecting-a-shard-key-for-mongodb ) help.
    – JJussi
    Jul 19, 2017 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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