发布于 2015-09-14 15:00:57 | 222 次阅读 | 评论: 0 | 来源: 网络整理
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.
也可以参考
分片 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..