sh.moveChunk()
On this page本页内容
Definition定义
sh.moveChunk(namespace, query, destination)
-
Moves the chunk that contains the document specified by the将包含query
to thedestination
shard.query
指定的文档的区块移动到destination
分片。sh.moveChunk()
provides a wrapper around the提供了moveChunk
database command.moveChunk
数据库命令的包装器。ImportantIn most circumstances, allow the balancer to automatically migrate chunks, and avoid calling在大多数情况下,允许平衡器自动迁移块,并避免直接调用sh.moveChunk()
directly.sh.moveChunk()
。WarningImportantmongosh Method
This page documents a
mongosh
method. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
moveChunk
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:sh.moveChunk()
takes the following arguments:接受以下参数:Parameter参数Type类型Description描述namespace
string The namespace of the sharded collection that contains the chunk to migrate.包含要迁移的区块的分片集合的命名空间。query
document An equality match on the shard key that selects the chunk to move.选择要移动的区块的分片键上的相等匹配。destination
string The 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从MongoDB 4.4开始,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.moveChunk
命令可以指定一个新选项forceJumbo
,以允许手动迁移太大而无法移动的块,无论是否使用jumbo
标签。See moveChunk command for details.有关详细信息,请参阅moveChunk
命令。
See also: 另请参阅:
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")