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:
sh.shardCollection(<namespace>, <key>) // Optional parameters omitted
| 指定您想要对其进行分片的集合的完整命名空间 ( |
|
有关分片方法的更多信息,请参阅 sh.shardCollection()。
分片键字段与字段值
缺少的分片键字段
分片集合中的文档可能缺少分片键字段。缺失的分片键与值为null 的分片键属于同一范围。请参阅缺少分片键字段。
更改文档的分区密钥值
您可以更新文档的分片键值,除非分片键字段是不可变的 _id 字段。
有关更新分片键值的详细信息,请参阅更改文档的分片键值。
更改集合的分片键
从 MongoDB 5.0 开始,您可以通过更改文档的分片键对集合重新分片。
您可以通过向现有分片键添加后缀字段或字段来优化分片键。