Definição
mergeChunksFor a sharded collection,
mergeChunkscombines contiguous chunk ranges on a shard into a single chunk. Issue themergeChunkscommand on theadmindatabase from amongosinstance.
Compatibilidade
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
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
Sintaxe
O comando tem a seguinte sintaxe:
db.adminCommand( { mergeChunks: <namespace>, bounds : [ { <shardKeyField>: <minFieldValue> }, { <shardKeyField>: <maxFieldValue> } ] } )
For compound shard keys, you must include the full shard key in the bounds specification. For example, if the shard key is { x: 1, y: 1 }, mergeChunks has the following form:
db.adminCommand( { mergeChunks: <namespace>, bounds: [ { x: <minValue>, y: <minValue> }, { x: <maxValue>, y: <maxValue> } ] } )
Campos de comando
O comando utiliza os seguintes campos:
Controle de acesso
Em sistemas executados com authorization, o role integrado clusterManager fornece os privilégios necessários.
Comportamento
Observação
Use the mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.
Para mesclar partes com êxito, o seguinte deve ser verdadeiro:
No campo
bounds,<minkey>e<maxkey>devem corresponder aos limites inferior e superior das partes a serem mesclados.As partes devem residir no mesmo fragmento.
As partes devem ser contíguos.
mergeChunks retorna um erro se estas condições não forem satisfeitas.
Retornar mensagens
On success, mergeChunks returns this document:
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
Outra operação em andamento
mergeChunks 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 balancer process, changes metadata while mergeChunks is running, you may see this error. You can retry the mergeChunks operation without side effects.
Parte em fragmentos diferentes
If the input chunks are not on the same shard, mergeChunks returns an error similar to the following:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users does not contain a chunk ending at { username: \"user63169\" }", "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
Blocos não contíguos
If the input chunks are not contiguous, mergeChunks returns an error similar to the following:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users has more than 2 chunks between [{ username: \"user29937\" }, { username: \"user49877\" })" "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }