- Sharding >
- Sharded Cluster Tutorials >
- Sharded Cluster Data Management >
- Merge Chunks in a Sharded Cluster
Merge Chunks in a Sharded Cluster¶
Overview¶
Changed in version 3.0.
The mergeChunks
command allows you to combine continuous
chunks on the same shard into a single chunk. This tutorial explains
how to merge neighboring chunks in a sharded cluster.
Procedure¶
Note
Examples in this procedure use a users
collection in the
test
database, using the username
filed as a
shard key.
Identify Chunk Ranges¶
In the mongo
shell, identify the chunk
ranges with the following operation:
The output of the sh.status()
will resemble the following:
The chunk ranges appear after the chunk counts for each sharded collection, as in the following excerpts:
Chunk counts:
Chunk range:
Merge Chunks¶
Merge two contiguous chunks on the same shard, with an operation that resembles the following:
On success, mergeChunks
produces the following output:
On any failure condition, mergeChunks
returns a document
where the value of the ok
field is 0
.
View Merged Chunks Ranges¶
After merging the identified chunks, confirm the new chunk, as follows:
The output of sh.status()
should resemble: