Profile slow queries mongodb
Capture ops slower than 100ms then read top offenders from system.profile
mongosh --eval 'db.setProfilingLevel(1,{slowms:100}); db.system.profile.find().sort({millis:-1}).limit(5)'
more mongodb
all 20 commands →
Connect with mongosh
mongosh 'mongodb://user:pass@mongo:27017/dbname'
Replica set status
mongosh --eval 'rs.status()' mongodb://mongo:27017
Database stats
mongosh --eval 'db.stats()' mongodb://mongo:27017/mydb
Collection stats
mongosh --eval 'db.myCollection.stats()' mongodb://mongo:27017/mydb
Current operations
mongosh --eval 'db.currentOp({active:true,secs_running:{$gt:5}})' mongodb://mongo:27017