Create dump
Export database to BSON files
mongodump --uri='mongodb://user:pass@mongo:27017' --db=mydb --out=/backups/
More mongodb commands
-
mongorestore --uri='mongodb://user:pass@mongo:27017' --db=mydb /backups/mydb/Import BSON backup into MongoDB
-
mongosh --eval 'db.myCollection.getIndexes()' mongodb://mongo:27017/mydbShow all indexes on a collection
-
mongosh 'mongodb+srv://user:pass@cluster.example.com/mydb'Connect to Atlas or any MongoDB URI with mongosh
-
db.orders.find({status:'new'}).explain('executionStats')Show execution stats including index usage
-
db.orders.createIndex({userId: 1, createdAt: -1}, {background: true})Ascending userId + descending createdAt index