MongoDB Shell Cheatsheet
Top commands.
Overview
The MongoDB shell cheatsheet captures the patterns operators actually use during MongoDB investigation. Fluency at the shell shortens incident response and informs schema decisions.
- Top commands.
find,aggregate,explain,stats,currentOp; the five that cover most investigation paths. - find with projection.
db.col.find({}, {field: 1}); reduces document size on the wire and at the client. - aggregate pipeline. Multi-stage transformations:
$match,$group,$lookup; the analytics surface inside the database. - explain plus currentOp.
explain("executionStats")for offline plans;currentOpfor live operations; together they answer "why is this slow?"
The approach
The practical approach: explain everything slow, projection by default, currentOp during incidents. The team's discipline produces fast investigation without needing a separate APM.
- explain("executionStats"). Plan plus runtime stats; reveals index miss, COLLSCAN, and stage timing in one output.
- aggregate with pipeline. Multi-stage transformations push computation to the database; reduces network and client load.
- currentOp({active: true}). Live operations during incidents; spot the long-running query before users do.
- serverStatus. Server-wide stats: connections, opcounters, wiredTiger cache; first call when investigating cluster-wide issues.
- Document queries. Per-collection access patterns committed to the repo; the team's institutional memory.
Why this compounds
MongoDB shell fluency compounds across incidents. Each query teaches a pattern; database expertise accrues; investigation gets faster over the team's tenure on the system.
- Faster debugging. Fluent shell reaches root cause in minutes; first-time-shell debugging takes hours.
- Better query performance.
explainexposes slow queries before they hit production scale; the team fixes them at PR time. - Live investigation.
currentOpcatches active issues mid-incident; aborts run-away queries; rescues the cluster. - Institutional knowledge. Each query taught teaches MongoDB internals; the team's database engineering muscle grows.
MongoDB shell fluency is an operational discipline that pays off across years. Nova AI Ops integrates with MongoDB telemetry, surfaces patterns, and supports the team's database engineering discipline.