- Reference >
- Database Commands >
- Sharding Commands >
- mergeChunks
mergeChunks¶
On this page
Definition¶
-
mergeChunks¶ For a sharded collection,
mergeChunkscombines contiguous chunk ranges on a shard into a single chunk. Issue themergeChunkscommand on theadmindatabase from amongosinstance.
Syntax¶
mergeChunks has the following form:
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:
Command Fields¶
The mergeChunks command takes the following fields:
| Field | Type | Description |
|---|---|---|
mergeChunks |
namespace | The fully qualified namespace of the collection
where both chunks exist. Namespaces take form of
<database>.<collection>. |
bounds |
array | An array that contains the minimum and maximum key values of the new chunk. |
Access Control¶
On deployments running with authorization, the
user must have access that includes the following privileges:
splitChunkaction on the collection.
The built-in role clusterManager provides the required
privileges.
Behavior¶
Note
Use the mergeChunks only in special circumstances. For
instance, when cleaning up your sharded cluster after removing
many documents.
In order to successfully merge chunks, the following must be true:
- In the
boundsfield,<minkey>and<maxkey>must correspond to the lower and upper bounds of the chunks to merge. - The chunks must reside on the same shard.
- The chunks must be contiguous.
mergeChunks returns an error if these conditions are not
satisfied.
Return Messages¶
On success, mergeChunks returns to following document:
Another Operation in Progress¶
mergeChunks returns the following error message if another
metadata operation is in progress on the chunks collection:
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.
Chunks on Different Shards¶
If the input chunks are not on the same shard,
mergeChunks returns an error similar to the following:
Noncontiguous Chunks¶
If the input chunks are not contiguous,
mergeChunks returns an error similar to the following: