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

Find COLLSCAN Queries in MongoDB

Lists queries doing collection scans in the profiler, with the examined-to-returned document ratio. The fastest way to find missing indexes.

#collscan#explain#missing-index
mongodb · javascript
db.system.profile.find(
  { planSummary: "COLLSCAN", ns: { $not: /system\.profile/ } },
  { ns: 1, op: 1, millis: 1, docsExamined: 1, nreturned: 1, command: 1, ts: 1 }
).sort({ millis: -1 }).limit(20);
Operational Notes & Remediation Guidance

COLLSCAN operations scan every document in the collection; add supporting indexes to eliminate collection scans.

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.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Related Alerts & Metrics
M52MongoDB WiredTiger Cache UsageMongoDB
M55MongoDB Scanned-to-Returned RatioMongoDB