liveBook · Manning

Top

As explained in MongoDB 8.0 in Action, Third Edition

top is a MongoDB diagnostic command that reports cumulative time and operation counts for reads and writes by database and collection.

top is a MongoDB diagnostic command for comparing cumulative read and write activity across databases and collections. It reports operation counts and elapsed time, helping reveal where workload and resource use concentrate. section 21.2.3

Use top when you need a workload-oriented view rather than a snapshot of currently running operations:

  • Run it from mongosh with db.runCommand({ top: 1 }). section 21.2.3
  • Compare total, read-lock, write-lock, query, getmore, insert, update, remove, and command time and counts. section 21.2.3
  • Use the results to identify busy namespaces and potential bottlenecks, then investigate active operations with currentOp or broader metrics with serverStatus. section 21.2.3 section 21.5

Inspect collection workload

Run db.runCommand({ top: 1 }). A namespace such as sample_training.routes may report total time 12000 across 150 operations, including 7000 query time, 3000 insert time, and 4000 update time. Compare these counters with other namespaces before choosing an optimization target. section 21.2.3

db.runCommand({ top: 1 })

Open the runnable mongosh command for querying top directly. section 21.2.3

sample_training.routes': {
  total: { time: 12000, count: 150 },
  readLock: { time: 7000, count: 80 },
  writeLock: { time: 5000, count: 70 },
  queries: { time: 7000, count: 80 },
  getmore: { time: 2000, count: 40 },
  insert: { time: 3000, count: 50 },
  update: { time: 4000, count: 60 },
  remove: { time: 1000, count: 20 },
  commands: { time: 500, count: 15 }}

Open a representative namespace result showing cumulative operation times and counts. section 21.2.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Reports cumulative counters and timing categories, but does not explain query plans or individual active-operation details.
Examples
Uses db.runCommand({ top: 1 }) and a sample_training.routes result containing read, write, query, insert, and update counters.
What you can do after
Diagnose workload hotspots and select collections or operation types for targeted performance investigation.
How it connects
Connects native diagnostics with currentOp, serverStatus, dbStats, collStats, and Atlas performance monitoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.