Migrate Chunks in a Sharded Cluster
- When pre-splitting an empty collection, migrate chunks manually to distribute them evenly across the shards. Use pre-splitting in limited situations to support bulk data ingestion.
- If the balancer in an active cluster cannot distribute chunks within the balancing window, then you will have to migrate chunks manually.
Migrate a single chunk
The following example assumes that the field
username is the shard key for a collection named
users in the
myapp database, and that the value
smith exists within the chunk to migrate. Migrate the chunk using the following command in the
This command moves the chunk that includes the shard key value “smith” to the shard named
mongodb-shard3.example.net. The command will block until the migration is complete.
To return a list of shards, use the
Evenly migrate chunks
To evenly migrate chunks for the
myapp.users collection, put each prefix chunk on the next shard from the other and run the following commands in the mongo shell:
See Create Chunks in a Sharded Cluster for an introduction to pre-splitting.
moveChunk command has the:
_secondaryThrottle parameter and the
writeConcern parameter that determines when the balancer proceeds with the next document in the migrating chunk. See
moveChunk command for details.