Connect with mongosh

Open interactive shell to a MongoDB instance

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

tool
mongodb20 commands
tags
mongodb

More mongodb commands

  • 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

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

    Export database to BSON files

all 20 mongodb commands