I have a collection with a relatively large index (but less than it has), and looking at the search performance in this collection and the amount of free bar in my system given by htop, it seems that mongo does not store the full index in RAM. Is there a way to get mongo to store this particular index in ram?
Request example:
> db.barrels.find({"tags":{"$all": ["avi"]}}).explain() { "cursor" : "BtreeCursor tags_1", "nscanned" : 300393, "nscannedObjects" : 300393, "n" : 300393, "millis" : 55299, "indexBounds" : { "tags" : [ [ "avi", "avi" ] ] } }
Not all objects are tagged with avi:
> db.barrels.find().explain() { "cursor" : "BasicCursor", "nscanned" : 823299, "nscannedObjects" : 823299, "n" : 823299, "millis" : 46270, "indexBounds" : { } }
Without "$ all":
db.barrels.find({"tags": ["avi"]}).explain() { "cursor" : "BtreeCursor tags_1 multi", "nscanned" : 300393, "nscannedObjects" : 300393, "n" : 0, "millis" : 43440, "indexBounds" : { "tags" : [ [ "avi", "avi" ], [ [ "avi" ], [ "avi" ] ] ] } }
This also happens when I look for two or more tags (it scans each element as if there was no index):
> db.barrels.find({"tags":{"$all": ["avi","mp3"]}}).explain() { "cursor" : "BtreeCursor tags_1", "nscanned" : 300393, "nscannedObjects" : 300393, "n" : 6427, "millis" : 53774, "indexBounds" : { "tags" : [ [ "avi", "avi" ] ] } }