Explain query plan mongodb
Show execution stats including index usage
db.orders.find({status:'new'}).explain('executionStats')
more mongodb
all 20 commands →
Create compound index
db.orders.createIndex({userId: 1, createdAt: -1}, {background: true})
Aggregation pipeline example
db.orders.aggregate([{$match:{status:'paid'}},{$group:{_id:'$userId',total:{$sum:'$amount'}}},{$sort:{total:-1}},{$limit:10}])
Check replication lag
rs.printSecondaryReplicationInfo()
Current operations (slow queries)
db.currentOp({active:true, secs_running:{$gt:5}})
Dump a database
mongodump --uri='mongodb://localhost:27017' --db=mydb --out=/backup/$(date +%F)