Para agentes de IA: hay un índice de documentación disponible en https://www.mongodb.com/es/docs/llms.txt — versiones en markdown de todas las páginas están disponibles agregando .md a cualquier ruta URL.
Docs Menu

mergeChunks (comando de base de datos)

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.

Este comando está disponible en implementaciones alojadas en los siguientes entornos:

  • MongoDB Atlas: El servicio totalmente gestionado para implementaciones de MongoDB en la nube
  • MongoDB Enterprise: La versión basada en suscripción y autogestionada de MongoDB

  • MongoDB Community: La versión de MongoDB con código fuente disponible, de uso gratuito y autogestionada.

El comando tiene la siguiente sintaxis:

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

El comando toma los siguientes campos:

Campo
Tipo
Descripción

mergeChunks

namespace

El namespace completamente calificado de la colección donde existen ambos fragmentos. Los namespaces toman la forma de <database>.<collection>.

bounds

arreglo

Un arreglo que contiene los valores mínimo y máximo de clave del nuevo fragmento.

En implementaciones que se ejecutan con authorization, el rol integrado clusterManager proporciona los privilegios necesarios.

Nota

Use the mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.

Para fusionar exitosamente los fragmentos, lo siguiente debe ser cierto:

  • En el campo bounds, <minkey> y <maxkey> deben corresponder a los límites inferior y superior de los fragmentos a fusionar.

  • Los fragmentos deben residir en la misma partición.

  • Los fragmentos deben ser contiguos.

mergeChunks retorna un error si estas condiciones no se cumplen.

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