The shardCollection command marks a collection for sharding and will allow data to begin distributing among shards. You must run enableSharding on a database before running the shardCollection command.
{ shardCollection: "<database>.<collection>", key: <shardkey> }
This enables sharding for the collection specified by <collection> in the database named <database>, using the key <shardkey> to distribute documents among the shard. <shardkey> is a document and takes the same form as an index specification document.
| Parameters: |
|
|---|
Choosing the right shard key to effectively distribute load among your shards requires some planning. Also review Shard Keys regarding choosing a shard key.
Warning
MongoDB provides no method to deactivate sharding for a collection after calling shardCollection. Additionally, after shardCollection, you cannot change shard keys or modify the value of any field used in your shard key index.
See also
Sharding, Sharded Cluster Overview, and Deploy a Sharded Cluster.