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
