title: MongoDB query optimization
body: <p>as my current task I have to optimize the indexes so that some of our queries run faster. I read this article: <a href="http://emptysqua.re/blog/optimizing-mongodb-compound-indexes/" rel="nofollow">http://emptysqua.re/blog/optimizing-mongodb-compound-indexes/</a><br>
  as this guys suggests My optimal query is when: </p>
  
  <pre><code> nscanned= nscannedObject = n  
  </code></pre>
  
  <p>Well, I was able to achieve that. The problem however that the query satisfying this formula is slower than the one does not ! 
  Here is my explain output :  </p>
  
  <pre><code>{
      "cursor" : "BtreeCursor previous_sticky_1",
      "nscanned" : 65019,
      "nscannedObjects" : 65019,
      "n" : 65019,
      "millis" : 5456,
      "nYields" : 76,
      "nChunkSkips" : 0,
      "isMultiKey" : false,
      "indexOnly" : false,
  }//everything is ok ( nscanned= nscannedObject = n ) 
  
  
  
    {
  "cursor" : "BtreeCursor subnetInfo.giAddr_1",
  "nscanned" : 65023,
  "nscannedObjects" : 65023,
  "n" : 65019,
  "scanAndOrder" : true,
  "millis" : 3355,
  "nYields" : 37,
  "nChunkSkips" : 0,
  "isMultiKey" : false,
  "indexOnly" : false
  </code></pre>
  
  <p>}
  // nscanned = nscannedObject > n but , "millis = 3355 &lt; 5456 " ??? </p>
  
  <p>Can you guys suggest why is that ? and which index to use ?  subnetInfo.giAddr_1 or previous_sticky_1 ?</p>