MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What are Targeted Queries vs Scatter-Gather Queries in Sharded Clusters?
senior LevelmongodbAdvanced Internals
In Simple Words:
- Targeted Query: The query includes the Shard Key in the
find()criteria.mongosroutes the query directly to the single exact shard holding that data. High performance, sub-5ms latency. - Scatter-Gather Query: The query does NOT include the shard key.
mongosmust broadcast the query to every single shard in the cluster, wait for all to respond, sort, and merge. Severely degrades cluster throughput at scale.