Chunk Migration
Chunk Migration: free step-by-step lesson with examples, common mistakes, and interview tips — part of MongoDB Tutorial on Toolliyo Academy.
On this page
MongoDB Tutorial · Lesson 69 of 100
Chunk Migration
Foundations & CRUD ✓ → Queries & Schema ✓ → Aggregation & Scale → Atlas & Projects
Aggregation & Scale · 3 — Pipelines · ~10 min · MongoDB — Replication & Sharding
What is this?
Chunks are contiguous ranges of shard key values stored on one shard. The balancer migrates chunks between shards to keep data size balanced. Migrations move documents and update config metadata.
Why should you care?
If one shard fills up while others are empty, inserts slow and disks risk filling. Balancing keeps capacity usable.
See it live — copy this example
Open mongosh or MongoDB Compass, select database nosqlverse, then run the example. Change one field and run again.
sh.getBalancerState()
sh.isBalancerRunning()
sh.startBalancer()
db.getSiblingDB("config").changelog.find({ what: /moveChunk/ }).sort({ time: -1 }).limit(3)
db.readings.getShardDistribution()
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- Balancer state shows whether automatic balancing is on.
- changelog records moveChunk events.
- getShardDistribution shows counts/sizes per shard after migrations.
- You can pause the balancer during peak sales if needed.
Practice next
- Check balancer state on a sharded cluster.
- Inspect distribution for a busy collection.
- Read recent moveChunk changelog entries.
- sh.disableAutoSplitter careful study in labs only.
- Identify jumbo chunks in sh.status().
Remember
Chunks are shard key ranges. Balancer migrates chunks for evenness. Watch distribution and changelog.
Rebalance after adding a shard
Ops adds a fourth shard; balancer migrates chunks onto it overnight.
Outcome: Write load spreads across the new capacity by morning.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!