Consider a sharded MongoDB cluster with a mongos router. When a query is sent to mongos, how does it decide which shards to query?
Think about how sharding improves query efficiency by targeting specific shards.
mongos uses the shard key in the query to determine which shards hold the relevant data. This avoids querying all shards and improves performance.
In a MongoDB sharded cluster, what is the primary role of the mongos process?
Think about how clients interact with a sharded cluster.
mongos acts as a router that directs client queries to the correct shards based on metadata. It does not store data or manage config servers.
Given a sharded collection with shard key { userId: 1 }, which mongos query will efficiently find documents for userId 123?
db.orders.find({ userId: 123 })Use the shard key field exactly in the query to target shards.
Querying by the shard key field userId allows mongos to route the query to the correct shard efficiently.
You notice that queries sent through mongos are slow because they query all shards. What change can optimize query performance?
Think about how mongos decides which shards to query.
Including the shard key in the query filter lets mongos route queries to only relevant shards, improving performance.
After a chunk migration in a sharded cluster, mongos sometimes returns stale data. What is the most likely cause?
Consider how mongos caches cluster metadata.
mongos caches metadata about chunk locations. After chunk migration, if it does not refresh this cache, it may route queries incorrectly and return stale data.