Query plan with stats mongodb
Show docs examined vs returned and index usage; COLLSCAN means missing index
mongosh --eval 'db.<name>.find({status:"active"}).explain("executionStats").executionStats'
more mongodb
all 20 commands →
Unused index detection
mongosh --eval 'db.<name>.aggregate([{$indexStats:{}}]).forEach(i=>print(i.name,i.accesses.ops))'
Profile slow queries
mongosh --eval 'db.setProfilingLevel(1,{slowms:100}); db.system.profile.find().sort({millis:-1}).limit(5)'
Connect with mongosh
mongosh 'mongodb://user:pass@mongo:27017/dbname'
Replica set status
mongosh --eval 'rs.status()' mongodb://mongo:27017
Database stats
mongosh --eval 'db.stats()' mongodb://mongo:27017/mydb