sh.moveChunk()

On this page本页内容

Definition定义

sh.moveChunk(namespace, query, destination)

Moves the chunk that contains the document specified by the query to the destination shard. 将包含query指定的文档的区块移动到destination分片。sh.moveChunk() provides a wrapper around the moveChunk database command.提供了moveChunk数据库命令的包装。

Important重要

In most circumstances, allow the balancer to automatically migrate chunks, and avoid calling sh.moveChunk() directly.在大多数情况下,允许平衡器自动迁移,并避免直接调用sh.moveChunk()

sh.moveChunk() takes the following arguments:采用以下参数:

Parameter参数Type类型Description描述
namespacestringThe namespace of the sharded collection that contains the chunk to migrate.包含要迁移的块的分片集合的命名空间
querydocumentAn equality match on the shard key that selects the chunk to move.分片键上的相等匹配,用于选择要移动的块。
destinationstringThe name of the shard to move.要移动的分片的名称。

By default, MongoDB cannot move a chunk if the number of documents in the chunk is greater than 1.3 times the result of dividing the configured chunk size by the average document size. 默认情况下,如果区块中的文档数大于配置区块大小除以平均文档大小所得结果的1.3倍,则MongoDB无法移动区块。Starting in MongoDB 4.4, the moveChunk command can specify a new option forceJumbo to allow for the manual migration of chunks too large to move, with or without the jumbo label. 从MongoDB 4.4开始,moveChunk命令可以指定一个新选项forceJumbo,以允许手动迁移太大而无法移动的块,无论是否使用jumbo标签。See moveChunk command for details.有关详细信息,请参阅moveChunk命令。

Example示例

Given the people collection in the records database, the following operation finds the chunk that contains the documents with the zipcode field set to 53187 and then moves that chunk to the shard named shard0019:给定records数据库中的people集合,以下操作将查找包含zipcode字段设置为53187的文档的区块,然后将该区块移动到名为shard0019的分片:

sh.moveChunk("records.people", { zipcode: "53187" }, "shard0019")
←  sh.isBalancerRunning()sh.removeShardTag() →