Bird
Raised Fist0
MongoDBquery~20 mins

Chunks and balancer concept in MongoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
MongoDB Sharding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary role of chunks in MongoDB sharding?
In MongoDB sharding, data is split into smaller parts called chunks. What is the main purpose of these chunks?
ATo create indexes on collections
BTo backup data automatically in the cluster
CTo encrypt data before storing it
DTo divide data into manageable pieces for distribution across shards
Attempts:
2 left
💡 Hint
Think about how data is shared across multiple servers.
❓ query_result
intermediate
2:00remaining
What does the balancer do in a MongoDB sharded cluster?
Consider a MongoDB sharded cluster where chunks are unevenly distributed. What is the balancer's role in this scenario?
AMoves chunks between shards to keep data evenly distributed
BDeletes old chunks to free up space
CCreates new chunks automatically when data grows
DMerges all chunks into a single shard
Attempts:
2 left
💡 Hint
Think about how the system keeps the data balanced across servers.
📝 Syntax
advanced
2:00remaining
Which MongoDB command shows the current chunk distribution across shards?
You want to check how chunks are distributed in your sharded cluster. Which command will give you this information?
Ash.getBalancerState()
Bdb.chunks.find()
Csh.status()
Ddb.shards.find()
Attempts:
2 left
💡 Hint
Look for the command that gives an overview of the sharding setup.
🔧 Debug
advanced
2:00remaining
Why might the balancer not move chunks even if data is uneven?
In a sharded cluster, the balancer is enabled but chunks are not moving to balance data. Which of the following is a likely cause?
AThe shard key is not defined
BThe balancer is paused or locked due to ongoing migrations
CChunks are too large and cannot be split further
DThe cluster has only one shard
Attempts:
2 left
💡 Hint
Think about what might temporarily stop the balancer from working.
❓ optimization
expert
3:00remaining
How can you optimize chunk size to improve balancer efficiency?
You notice the balancer is moving chunks too frequently, causing overhead. What is a good way to optimize chunk size for better balancer performance?
AIncrease the chunk size to reduce the number of chunks
BDecrease the chunk size to create more chunks
CDisable the balancer permanently
DRemove the shard key from the collection
Attempts:
2 left
💡 Hint
Think about how chunk size affects how often chunks move.

Practice

(1/5)
1. What is the main purpose of chunks in MongoDB sharding?
easy
A. To backup data automatically
B. To create indexes on collections
C. To encrypt data for security
D. To split data into smaller parts for easier management

Solution

  1. Step 1: Understand the role of chunks in sharding

    Chunks divide large data sets into smaller pieces to distribute across servers.
  2. Step 2: Identify the purpose of chunking

    This splitting helps manage and query data efficiently in a distributed system.
  3. Final Answer:

    To split data into smaller parts for easier management -> Option D
  4. Quick Check:

    Chunks split data = To split data into smaller parts for easier management [OK]
Hint: Chunks break data into parts for easier handling [OK]
Common Mistakes:
  • Confusing chunks with backups
  • Thinking chunks encrypt data
  • Assuming chunks create indexes
2. Which of the following is the correct command to check the balancer status in MongoDB?
easy
A. sh.status()
B. db.balancerStatus()
C. sh.isBalancerRunning()
D. sh.getBalancerState()

Solution

  1. Step 1: Recall MongoDB shell commands for sharding

    The sh.status() command shows the sharding status including balancer info.
  2. Step 2: Verify other options

    Other commands are not valid MongoDB shell commands for balancer status.
  3. Final Answer:

    sh.status() -> Option A
  4. Quick Check:

    Balancer status command = sh.status() [OK]
Hint: Use sh.status() to see balancer info quickly [OK]
Common Mistakes:
  • Using non-existent commands like db.balancerStatus()
  • Confusing balancer commands with other shell commands
  • Assuming sh.getBalancerState() exists
3. Consider a sharded collection with chunks distributed unevenly. What will the balancer do when it runs?
medium
A. Move chunks from overloaded shards to underloaded shards
B. Delete chunks from overloaded shards
C. Merge all chunks into one big chunk
D. Create new chunks on the busiest shard

Solution

  1. Step 1: Understand balancer's role in chunk distribution

    The balancer moves chunks to spread data evenly across shards.
  2. Step 2: Identify the correct action for uneven chunk distribution

    It migrates chunks from overloaded shards to those with less data to balance load.
  3. Final Answer:

    Move chunks from overloaded shards to underloaded shards -> Option A
  4. Quick Check:

    Balancer moves chunks to balance load = Move chunks from overloaded shards to underloaded shards [OK]
Hint: Balancer moves chunks to balance shard load [OK]
Common Mistakes:
  • Thinking balancer deletes chunks
  • Assuming balancer merges chunks
  • Believing balancer creates chunks on busy shards
4. You run sh.startBalancer() but the balancer does not start. What is a likely cause?
medium
A. Chunks are too small to move
B. Balancer is disabled in the config server
C. Balancer is already running
D. No shards exist in the cluster

Solution

  1. Step 1: Check balancer configuration

    If balancer is disabled in the config server, it won't start even if commanded.
  2. Step 2: Evaluate other options

    Balancer already running would not prevent start command; chunk size doesn't block start; shards must exist for sharding.
  3. Final Answer:

    Balancer is disabled in the config server -> Option B
  4. Quick Check:

    Balancer disabled in config = won't start [OK]
Hint: Check config server if balancer won't start [OK]
Common Mistakes:
  • Assuming balancer can't start if already running
  • Thinking chunk size blocks balancer start
  • Ignoring config server settings
5. A MongoDB cluster has uneven chunk distribution causing slow queries on one shard. You want to manually trigger chunk migration to balance load. Which command should you use?
hard
A. sh.shardCollection('db.collection', { shardKey: 1 })
B. sh.splitChunk('db.collection', { shardKey: value })
C. sh.moveChunk('db.collection', { shardKey: value }, 'toShard')
D. sh.enableBalancer()

Solution

  1. Step 1: Identify command to move chunks manually

    sh.moveChunk() moves a specific chunk to a target shard manually.
  2. Step 2: Differentiate from other commands

    sh.splitChunk() splits chunks, sh.enableBalancer() enables automatic balancing, and sh.shardCollection() enables sharding on a collection.
  3. Final Answer:

    sh.moveChunk('db.collection', { shardKey: value }, 'toShard') -> Option C
  4. Quick Check:

    Manual chunk move = sh.moveChunk() [OK]
Hint: Use sh.moveChunk() to manually move chunks [OK]
Common Mistakes:
  • Using splitChunk to move chunks
  • Confusing enabling balancer with moving chunks
  • Trying to shard collection again instead of moving chunks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard