This version of the documentation is archived and no longer supported.



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: "<db>.<collection>", key: <shardkey> }

This enables sharding for the collection specified by <collection> in the database named <db>, using the key <shardkey> to distribute documents among the shard. <shardkey> is a document, and takes the same form as an index specification document.

Choosing the right shard key to effectively distribute load among your shards requires some planning.

See also

Sharding for more information related to sharding. Also consider the section on Shard Key Selection for documentation regarding shard keys.


There’s no easy way to disable sharding after running shardCollection. In addition, you cannot change shard keys once set. If you must convert a sharded cluster to a standalone node or replica set, you must make a single backup of the entire cluster and then restore the backup to the standalone mongod or the replica set..