List indexes mongodb
Show all indexes on a collection
mongosh --eval 'db.myCollection.getIndexes()' mongodb://mongo:27017/mydb
more mongodb
all 20 commands →
Connect with URI
mongosh 'mongodb+srv://user:pass@cluster.example.com/mydb'
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()