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

sh.moveChunk()(mongosh方法)

sh.moveChunk(namespace, query, destination)

Moves the chunk that contains the document specified by the query to the destination shard. sh.moveChunk() provides a wrapper around the moveChunk database command.

重要

In most circumstances, allow the balancer to automatically migrate chunks, and avoid calling sh.moveChunk() directly.

警告

此命令不能用于哈希分片键,因为它使用moveChunk命令中的find选项。 要移动带有哈希分片键的数据块,请使用moveChunk命令并指定bounds字段。

重要

mongosh 方法

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

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

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

sh.moveChunk() 采用以下参数:

Parameter
类型
说明

namespace

字符串

包含要迁移的数据块的分片collection的命名空间

query

文档

选择要移动的数据块的分片键的等值匹配。

destination

字符串

接收分片的ID 。

默认,如果数据段中的数据块数据块大于配置的数据段数据块除以平均文档大小所得结果的2倍,则MongoDB无法移动该数据段。 moveChunk命令可以指定forceJumbo选项,以允许手动迁移太大而无法移动的数据段,无论是否带有jumbo标签。 有关详细信息,请参阅moveChunk命令。

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

重要

M0 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。

给定records数据库中的peoplecollection,以下操作查找包含zipcode字段设置为53187的文档的数据块,然后将该数据块移动到名为shard0019的分片:

sh.moveChunk("records.people", { zipcode: "53187" }, "shard0019")
给本页内容打分

在此页面上