Connect with URI mongodb
Connect to Atlas or any MongoDB URI with mongosh
mongosh 'mongodb+srv://user:pass@cluster.example.com/mydb'
more mongodb
all 20 commands →
Explain query plan
db.orders.find({status:'new'}).explain('executionStats')
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}})