Profile slow queries

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

tool
mongodb20 commands
tags
mongodbperformancetroubleshootingobservability

More mongodb commands

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

    Open interactive shell to a MongoDB instance

  • mongosh --eval 'rs.status()' mongodb://mongo:27017

    Show replica set members, lag, and election status

  • mongosh --eval 'db.stats()' mongodb://mongo:27017/mydb

    Data size, storage size, collection count for a database

  • mongosh --eval 'db.myCollection.stats()' mongodb://mongo:27017/mydb

    Document count, index sizes, storage for a collection

  • mongosh --eval 'db.currentOp({active:true,secs_running:{$gt:5}})' mongodb://mongo:27017

    Show operations running longer than 5 seconds

all 20 mongodb commands