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

sh.moveRange()(mongosh方法)

sh.moveRange(namespace, toShard, min, max)

6.0版本新增。

在分片之间移动范围。

重要

mongosh 方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

有关数据库命令,请参阅 moveRange 命令。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

sh.moveRange(namespace, toShard, min, max)

sh.moveRange() 方法采用以下参数:

Parameter
类型
说明

namespace

字符串

设置要移动范围的数据库和集合。

toShard

字符串

设置用于接收范围的分片的ID 。

min

文档

要移动范围的最小键。

max

文档

要移动范围的最大键。

以下示例使用具有以下内容的集合:

  • 分片键 postal,表示邮政编码。

  • 边界为 70007 和 70124 的范围。

要将邮政范围移至 shard02,运行以下方法:

sh.moveRange(
"contacts.addresses", "shard02",
{ postal: 70007 },
{ postal: 70124 }
)
{
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1742507819, i: 42 }),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1742507819, i: 42 })
}
给本页内容打分