Unused index detection mongodb
Access count per index; zero ops = candidate to drop and reclaim write cost
mongosh --eval 'db.<name>.aggregate([{$indexStats:{}}]).forEach(i=>print(i.name,i.accesses.ops))'
more mongodb
all 20 commands →
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
Collection stats
mongosh --eval 'db.myCollection.stats()' mongodb://mongo:27017/mydb