Find slow operations
List operations that run longer than 5 seconds
db.currentOp({active:true, secs_running:{$gt:5}})
- tool
- mongodb20 commands
More mongodb commands
-
mongodump --uri='mongodb://localhost:27017' --db=mydb --out=/backup/$(date +%F)Dump all collections of a database to BSON files in a dated folder
-
mongosh --eval 'rs.status().members.forEach(m=>print(m.name,m.stateStr,m.optimeDate))'Show the state and last applied optime of each member to find lagging or unhealthy secondaries
-
mongosh --eval 'db.currentOp({secs_running:{$gt:5},op:{$ne:"none"}}).inprog.forEach(o=>{print(o.opid,o.secs_running,o.ns); db.killOp(o.opid)})'Find operations running longer than 5s and kill each with killOp. killOp is async, so check the result afterwards
-
mongosh --eval 'db.<name>.find({status:"active"}).explain("executionStats").executionStats'Compare documents examined and returned and check index usage. COLLSCAN means there is no index
-
mongosh --eval 'db.<name>.aggregate([{$indexStats:{}}]).forEach(i=>print(i.name,i.accesses.ops))'Show how often each index is used. An index with zero ops is a candidate to drop and makes writes cheaper