0
0
MongoDBquery~20 mins

Mongos router behavior in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Mongos Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
How does mongos route a query to shards?

Consider a sharded MongoDB cluster with a mongos router. When a query is sent to mongos, how does it decide which shards to query?

AIt broadcasts the query to all shards regardless of shard key.
BIt uses the shard key in the query to route the query only to relevant shards.
CIt sends the query only to the primary shard of the database.
DIt randomly selects one shard to send the query to.
Attempts:
2 left
💡 Hint

Think about how sharding improves query efficiency by targeting specific shards.

🧠 Conceptual
intermediate
2:00remaining
What role does mongos play in a sharded cluster?

In a MongoDB sharded cluster, what is the primary role of the mongos process?

AIt acts as a query router and interface between clients and shards.
BIt stores the actual data for the shards.
CIt manages the config servers and metadata storage.
DIt performs backups of the cluster data.
Attempts:
2 left
💡 Hint

Think about how clients interact with a sharded cluster.

📝 Syntax
advanced
2:00remaining
Identify the correct mongos query to find documents by shard key

Given a sharded collection with shard key { userId: 1 }, which mongos query will efficiently find documents for userId 123?

MongoDB
db.orders.find({ userId: 123 })
Adb.orders.find({ userId: 123 })
Bdb.orders.find({ _id: 123 })
Cdb.orders.find({ userId: { $gt: 100 } })
Ddb.orders.find({ customerId: 123 })
Attempts:
2 left
💡 Hint

Use the shard key field exactly in the query to target shards.

optimization
advanced
2:00remaining
How to optimize queries with mongos in a sharded cluster?

You notice that queries sent through mongos are slow because they query all shards. What change can optimize query performance?

ARun queries directly on config servers instead of mongos.
BIncrease the number of shards to distribute load.
CAdd the shard key to the query filter to target specific shards.
DDisable sharding on the collection.
Attempts:
2 left
💡 Hint

Think about how mongos decides which shards to query.

🔧 Debug
expert
3:00remaining
Why does mongos return stale data after chunk migration?

After a chunk migration in a sharded cluster, mongos sometimes returns stale data. What is the most likely cause?

AThe client query is missing the shard key field.
BThe shard key was changed during migration causing data loss.
CConfig servers are offline and cannot update mongos.
Dmongos has cached outdated metadata and has not refreshed it yet.
Attempts:
2 left
💡 Hint

Consider how mongos caches cluster metadata.