I have a vague memory that MongoDB will output to its log a message if a query uses fields that are not indexed, however I am unable to reproduce this locally (with an admittedly small dataset) nor have I found any documentation for it.
Am I imagining things or is there such a feature? If yes, can anyone link to documentation?
You need to turn on profiling to get a meaningful log from mongodb - setting profiling to 1 is sufficient.
You can then find unindexed queries using any number of searches in the log, e.g.:
grep nscanned /path/to/mongodb.log | grep -v "nscanned:1 " | grep -v "nscanned:0 "
Original tweet where I found out about this: https://twitter.com/#!/eonwhite/status/21498320559
You can see more about what the log output means in mongo's docs
If nscanned is much higher than nreturned, the database is scanning many objects to find the target objects. Consider creating an index to improve this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With