title: Is there a way to force mongodb to store certain index in ram?
body: <p>I have a collection with a relatively big index (but less than ram available)  and looking at performance of find on this collection and amount of free ram in my system given by htop it's seems that mongo is not storing full index in the ram. Is there a way to force mongo to store this particular index in the ram?</p>
  
  <p>Example query:</p>
  
  <pre><code>&gt; db.barrels.find({"tags":{"$all": ["avi"]}}).explain()
  {
          "cursor" : "BtreeCursor tags_1",
          "nscanned" : 300393,
          "nscannedObjects" : 300393,
          "n" : 300393,
          "millis" : 55299,
          "indexBounds" : {
                  "tags" : [
                          [
                                  "avi",
                                  "avi"
                          ]
                  ]
          }
  }
  </code></pre>
  
  <p>Not the all objects are tagged with "avi" tag:</p>
  
  <pre><code>&gt; db.barrels.find().explain()
  {
          "cursor" : "BasicCursor",
          "nscanned" : 823299,
          "nscannedObjects" : 823299,
          "n" : 823299,
          "millis" : 46270,
          "indexBounds" : {
  
          }
  }
  </code></pre>
  
  <p>Without "$all":</p>
  
  <pre><code>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"
                                  ]
                          ]
                  ]
          }
  }
  </code></pre>
  
  <p>Also this happens when I search for two or more tags (it scans every item as if were no index):</p>
  
  <pre><code>&gt; db.barrels.find({"tags":{"$all": ["avi","mp3"]}}).explain()
  {
          "cursor" : "BtreeCursor tags_1",
          "nscanned" : 300393,
          "nscannedObjects" : 300393,
          "n" : 6427,
          "millis" : 53774,
          "indexBounds" : {
                  "tags" : [
                          [
                                  "avi",
                                  "avi"
                          ]
                  ]
          }
  }
  </code></pre>