ANNOUNCEMENT: Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas.
Learn more
Menu Docs

moveChunk

moveChunk

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

Dica

Em mongosh, esse comando também pode ser executado por meio do método auxiliar sh.moveChunk().

Os métodos auxiliares são práticos para os usuários mongosh, mas podem não retornar o mesmo nível de informações que os comandos do banco de dados. Nos casos em que a praticidade não for necessária ou os campos de retorno adicionais forem necessários, use o comando de banco de dados.

db.adminCommand( { moveChunk : <namespace> ,
find : <query> ,
to : <string>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

Alternatively:

db.adminCommand( { moveChunk : <namespace> ,
bounds : <array> ,
to : <string>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

The moveChunk command has the following fields:

Campo
Tipo
Descrição

moveChunk

string

The namespace of the collection where the chunk exists. Specify the collection's full namespace, including the database name.

find

documento

An equality match on the shard key that specifies the shard-key value of the chunk to move. Specify either the bounds field or the find field but not both. Do não use the find field to select chunks in collections that use a hashed shard key.

bounds

array

The bounds of a specific chunk to move. The array must consist of two documents that specify the lower and upper shard key values of a chunk to move. Specify either the bounds field or the find field but not both. Use bounds to select chunks in collections that use a hashed shard key.

to

string

The name of the destination shard for the chunk.

booleano

Optional. A flag that determines if the command can move a chunk that is too large to migrate. The chunk may or may not be labeled as jumbo.

  • If true, the command can move the chunk.

  • If false, the command cannot move the chunk.

O padrão é false.

AVISO:

O comando moveChunk com forceJumbo=true blocos escreve operações na collection.

Essa opção faz com que o shard migre chunks mesmo quando eles são maiores do que o tamanho configurado do chunk. A collection permanece indisponível para gravações durante a migração.

Para migrar esses grandes blocos sem esse longo período de bloqueio, consulte Intervalos de equilíbrio que excedem o limite de tamanho .

_secondaryThrottle

booleano

Optional. For wiredTiger, defaults to false.

  • If true, then by default, each document move during chunk migration propagates to at least one secondary before the balancer proceeds with the next document. This is equivalent to a write concern of { w: 2 }.

    Use the writeConcern option to specify a different write concern.

  • Se false, o balanceador não aguarda a replicação em um secundário e, em vez disso, continua com o próximo documento.

Para obter mais informações, consulte Acelerador secundário.

writeConcern

documento

Optional. A document that expresses the Escreva preocupação that the _secondaryThrottle will use to wait for secondaries during the chunk migration.

writeConcern requires _secondaryThrottle: true.

_waitForDelete

booleano

Optional. Internal option for testing purposes. The default is false. If set to true, the delete phase of a moveChunk operation blocks.

When the _waitForDelete field is set, MongoDB does not wait on the orphanCleanupDelaySecs delay before performing the range deletion. If you use the _waitForDelete parameter and have any read operations occurring on secondaries, the read may miss documents due to the migration's delete phase.

The value of bounds takes the form:

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

The chunk migration section describes how chunks move between shards on MongoDB.

Veja também:

Esse comando está disponível em implantações hospedadas nos seguintes ambientes:

  • MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem

Importante

Este comando não é suportado em instâncias sem servidor. Para obter mais informações, consulte Comandos não suportados.

  • MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB

  • MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB

Only use the moveChunk in special circumstances such as preparing your cluster fragmentado 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 Criar faixas em um cluster fragmentado 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.