Show collection stats

Show document count, index sizes and storage size of a collection

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

tool
mongodb20 commands
tags
mongodb

More mongodb commands

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

    Show operations that run longer than 5 seconds

  • mongodump --uri='mongodb://user:pass@mongo:27017' --db=mydb --out=/backups/

    Export a database to BSON files

  • mongorestore --uri='mongodb://user:pass@mongo:27017' --db=mydb /backups/mydb/

    Load a BSON backup into MongoDB

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

    Show all indexes of a collection

  • mongosh 'mongodb+srv://user:pass@cluster.example.com/mydb'

    Connect to Atlas or any MongoDB URI with mongosh

all 20 mongodb commands