Restore a dump

Load a BSON backup into MongoDB

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

tool
mongodb20 commands
tags
mongodb

More mongodb commands

  • 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

  • db.orders.find({status:'new'}).explain('executionStats')

    Show execution stats, including index usage

  • db.orders.createIndex({userId: 1, createdAt: -1}, {background: true})

    Index on userId ascending and createdAt descending (`background` is ignored since MongoDB 4.2)

  • db.orders.aggregate([{$match:{status:'paid'}},{$group:{_id:'$userId',total:{$sum:'$amount'}}},{$sort:{total:-1}},{$limit:10}])

    Top 10 users by total amount of paid orders

all 20 mongodb commands