sh.moveChunk()
On this page本页内容
Definition定义
sh.moveChunk(namespace, query, destination)-
Moves the chunk that contains the document specified by the将包含queryto thedestinationshard.query指定的文档的区块移动到destination分片。sh.moveChunk()provides a wrapper around the提供了moveChunkdatabase 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
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
moveChunkcommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:sh.moveChunk()takes the following arguments:接受以下参数:Parameter参数Type类型Description描述namespacestring The namespace of the sharded collection that contains the chunk to migrate.包含要迁移的区块的分片集合的命名空间。querydocument An equality match on the shard key that selects the chunk to move.选择要移动的区块的分片键上的相等匹配。destinationstring 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开始,moveChunkcommand 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")