对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

将集合分片

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

namespace

指定您想要对其进行分片的集合的完整命名空间 ("<database>.<collection>")。

key

指定文档 { <shard key field1>: <1|"hashed">, ... },其中

有关分片方法的更多信息,请参阅 sh.shardCollection()

分片集合中的文档可能缺少分片键字段。缺失的分片键与值为null 的分片键属于同一范围。请参阅缺少分片键字段。

您可以更新文档的分片键值,除非分片键字段是不可变的 _id 字段。

有关更新分片键值的详细信息,请参阅更改文档的分片键值

从 MongoDB 5.0 开始,您可以通过更改文档的分片键对集合重新分片

您可以通过向现有分片键添加后缀字段或字段来优化分片键