Check replication lag mongodb
Show secondary lag and oplog window
rs.printSecondaryReplicationInfo()
more mongodb
all 20 commands →
Current operations (slow queries)
db.currentOp({active:true, secs_running:{$gt:5}})
Dump a database
mongodump --uri='mongodb://localhost:27017' --db=mydb --out=/backup/$(date +%F)
Replica set status
mongosh --eval 'rs.status().members.forEach(m=>print(m.name,m.stateStr,m.optimeDate))'
Kill long-running ops
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)})'
Query plan with stats
mongosh --eval 'db.<name>.find({status:"active"}).explain("executionStats").executionStats'