To shard a collection, you must specify the full namespace of the collection that you want to shard and the shard key. 要对集合进行分片,您必须指定要分片的集合的完整命名空间和分片键。You can use the 您可以使用mongosh method sh.shardCollection() to shard a collection:mongosh方法sh.shardCollection()对集合进行分片:
sh.shardCollection(<namespace>, <key>) // Optional parameters omitted
namespace | "<database>.<collection>")."<database>.<collection>")。 |
key |
|
For more information on the sharding method, see 有关分片方法的更多信息,请参阅sh.shardCollection().sh.shardCollection()。
Shard Key Fields and Values分片键段和值
Missing Shard Key Fields缺少分片键段
Documents in sharded collections can be missing the shard key fields. A missing shard key falls into the same range as a 分片集合中的文档可能缺少分片键字段。缺失的分片键与null-valued shard key. null值分片键属于同一范围。See Missing Shard Key Fields.请参见缺少的分片键段。
Change a Document's Shard Key Value更改文档的分片键值
You can update a document's shard key value unless the shard key field is the immutable 您可以更新文档的分片键值,除非分片键字段是不可变的_id field._id字段。
For details on updating the shard key value, see Change a Document's Shard Key Value.有关更新分片键值的详细信息,请参阅更改文档的分片键值。
Change a Collection's Shard Key更改集合的分片键
Starting in MongoDB 5.0, you can reshard a collection by changing a document's shard key.从MongoDB 5.0开始,您可以通过更改文档的分片键来重新分片集合。
You can refine a shard key by adding a suffix field or fields to the existing shard key.您可以通过向现有分片键添加一个或多个后缀字段来细化分片键。