dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mongodb/#99
Script #99
mongodb
Performanceread-onlyMin Version: 4.0

Scatter-Gather Queries in a Sharded MongoDB Cluster

Measures queries fanning out to all shards via mongos. Used to evaluate shard key choice and query targeting.

#sharding#scatter-gather#mongos
mongodb · javascript
db.serverStatus().metrics.queryExecutor;

// mongos üzerinde hedefleme oranı: scannedObjects / returned ne kadar yüksekse,
// sorgu o kadar çok shard'a dağılıyor demektir.
db.getSiblingDB("admin").runCommand({ serverStatus: 1 }).metrics.query;
Operational Notes & Remediation Guidance

Queries without shard key predicates target all shards (scatter-gather), causing network overhead and latency spikes.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 4.0).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.