Replica set status

Per-member state and last applied optime; spot lagging or unhealthy secondaries

mongosh --eval 'rs.status().members.forEach(m=>print(m.name,m.stateStr,m.optimeDate))'

tool
mongodb20 commands
tags
mongodbmonitoringtroubleshootingobservability

More mongodb commands

  • 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)})'

    List queries running >5s with ns then killOp each; note: killOp is async, verify after

  • mongosh --eval 'db.<name>.find({status:"active"}).explain("executionStats").executionStats'

    Show docs examined vs returned and index usage; COLLSCAN means missing index

  • mongosh --eval 'db.<name>.aggregate([{$indexStats:{}}]).forEach(i=>print(i.name,i.accesses.ops))'

    Access count per index; zero ops = candidate to drop and reclaim write cost

  • mongosh --eval 'db.setProfilingLevel(1,{slowms:100}); db.system.profile.find().sort({millis:-1}).limit(5)'

    Capture ops slower than 100ms then read top offenders from system.profile

  • mongosh 'mongodb://user:pass@mongo:27017/dbname'

    Open interactive shell to a MongoDB instance

all 20 mongodb commands