Shard a collection
MongoDBShardingCommand
sh.shardCollection("shop.customer", { customerId: "hashed" })What it does
Shards the specified collection on the given shard key.
When to use it
When you want to distribute a growing collection across multiple shards.
Caution
The shard key can be changed with reshardCollection in 5.0+ (and extended with refineCollectionShardKey in 4.4+), but this is expensive because it redistributes all of the data; a poor key choice leads to uneven distribution.