Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

mesclarChunks (comando de banco de dados)

mergeChunks

For a sharded collection, mergeChunks combines contiguous chunk ranges on a shard into a single chunk. Issue the mergeChunks command on the admin database from a mongos instance.

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

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> }
]
}
)

O comando utiliza os seguintes campos:

Campo
Tipo
Descrição

mergeChunks

namespace

O namespace totalmente qualificado da coleção onde existem ambos os blocos . Os namespaces assumem a forma de <database>.<collection>.

bounds

array

Uma array que contém os valores de chave mínimos e máximos do novo chunk.

Em sistemas executados com authorization, o role integrado clusterManager fornece os privilégios necessários.

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.

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)
}

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.

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)
}

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)
}