Reputation: 15767
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?
Upvotes: 4
Views: 5436
Reputation: 7426
You might be thinking of the notablescan
parameter and configuration option. However, it's not a warning or logging feature. Instead, it causes the server to throw an error whenever a query is made for which there is no useful index (forcing the server to scan the entire collection).
Upvotes: 4
Reputation: 66218
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.
Upvotes: 5
Reputation: 1333
perhaps you are referring to the "explain" functionality?
see this link: http://www.mongodb.org/display/DOCS/Explain
Basically, you can tell Mongo to give you extra data when you run a query, that data including details about whether or not an index was used.
Upvotes: 3
Reputation: 12510
AFAIK there's no direct signs of it in the log or anywhere else. Indirectly missing indexes can result in these log entries:
warning: ClientCursor::yield can't unlock b/c of recursive lock
- usually happens with findAndModify
.query db.coll nscanned:656204 reslen:20 5305ms
- slow query with big number of scanned documents.Neither of above will show up if the corresponding queries execute fast enough.
Upvotes: 0