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

moveChunk(数据库命令)

moveChunk

Internal administrative command. Moves chunks between shards. Issue the moveChunk command via a mongos instance while using the admin database. Use the following forms:

提示

In mongosh, this command can also be run through the sh.moveChunk() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

db.adminCommand( { moveChunk : <namespace> ,
find : <query> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

或者:

db.adminCommand( { moveChunk : <namespace> ,
bounds : <array> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

注意

使用 listShards 命令检索接收分片的ID 。

The moveChunk command has the following fields:

字段
类型
说明

moveChunk

字符串

数据块 所在 collection的 命名空间 。指定集合的完整命名空间,包括数据库名称。

find

文档

分片键的等值匹配,用于指定要移动的数据段的分片键值。 指定bounds字段或find字段,但不能同时指定两者。 请勿使用find字段来选择使用哈希分片键的集合中的数据段。

bounds

阵列

要移动的特定数据块的边界。该数组必须由两个文档组成,这两个文档指定要移动的数据段的下分片键值和上分片键值。 指定bounds字段或find字段,但不能同时指定两者。 使用bounds选择使用哈希分片键的collection中的数据块。

to

字符串

数据块的接收分片片的ID 。

布尔

可选。 一个标志,用于确定该命令是否可以移动过大而无法迁移的数据块。该数据段可能会也可能不会标记为jumbo。

  • 如果为true ,则该命令可以移动数据块。

  • 如果为false ,则该命令无法移动数据块。

默认为 false。

警告:

附带 forceJumbo=true 的 moveChunk 命令会阻止集合上的写入操作。

此选项会导致分片迁移数据段,即使数据段大于配置的数据块大小。 在迁移期间,该集合仍然不可写入。

要在没有这么长的阻塞期的情况下迁移这些大数据段,请参阅平衡超出大小限制的范围。

_secondaryThrottle

布尔

可选。 对于WiredTiger ,默认为false 。

  • 如果true ,则默认情况下,数据段迁移期间的每个文档移动都会传播到至少一个从节点,然后负载均衡器才会继续处理下一个文档。 这相当于 写关注(write{ w: 2 } concern)的。

    使用writeConcern选项指定不同的写关注(write concern)。

  • 如果为false ,负载均衡器不会等待复制到从节点,而是继续处理下一个文档。

有关更多信息,请参阅辅助限制。

writeConcern

文档

可选。 一个表达写关注(write concern)的文档,在数据块迁移期间, _secondaryThrottle将使用该写关注(write concern)来等待从节点。

writeConcern 需要_secondaryThrottle: true 。

_waitForDelete

布尔

Optional. If set to true, the delete phase of a moveChunk operation is blocking. _waitForDelete defaults to false.

当 _waitForDelete字段设立为 true 时, MongoDB在执行范围删除之前不会等待 orphanCleanupDelaySecs 延迟。如果您使用 _waitForDelete 参数并在从节点上执行任何读取操作,则读取可能会由于迁移的删除阶段而终止。要学习;了解详情,请参阅 terminateSecondaryReadsOnOrphanCleanup。

bounds的值采用以下形式:

[ { hashedField : <minValue> } ,
{ hashedField : <maxValue> } ]

数据块迁移部分描述了数据块如何在 MongoDB 上的分片之间移动。

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

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

Only use the moveChunk in special circumstances such as preparing your sharded cluster for an initial ingestion of data, or a large bulk import operation. In most cases allow the balancer to create and balance chunks in sharded clusters. See Create Ranges in a Sharded Cluster for more information.

moveChunk requires that all indexes exist on the target (i.e. to ) shard before migration and returns an error if a required index does not exist.

moveChunk returns the following error message if another metadata operation is in progress on the chunks collection:

errmsg: "The collection's metadata lock is already taken."

If another process, such as a balancer process, changes meta data while moveChunk is running, you may see this error. You may retry the moveChunk operation without side effects.

Starting in MongoDB 5.0, you can set the maxCatchUpPercentageBeforeBlockingWrites to specify the maximum allowed percentage of data not yet migrated during a moveChunk operation when compared to the total size (in MBs) of the chunk being transferred.

给本页内容打分