Query plan with stats

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

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

tool
mongodb20 commands
tags
mongodbperformancetroubleshootingdebug

More mongodb commands

  • 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

  • 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

all 20 mongodb commands