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
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.
-
-
_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.– JJussiJul 19, 2017 at 4:29