title: Unable to get a covered query to use index only in mongodb
body: <p>I am trying to use a covering index to implement stemming text search on my app which uses mongodb.</p>
  
  <p>I've got the following index set:</p>
  
  <pre><code>ensureIndex({st: 1, n: 1, _id: 1});
  </code></pre>
  
  <p>But when I run explain() on my query, I can never get the indexOnly to read true, no matter what I do.</p>
  
  <pre><code>db.merchants.find({st: "Blue"}, {n:1,_id:1}).explain()
  {
      "cursor" : "BtreeCursor st_1_n_1__id_1",
      "nscanned" : 8,
      "nscannedObjects" : 8,
      "n" : 8,
      "millis" : 0,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : true,
      "indexOnly" : false,
      "indexBounds" : {
          "st" : [
              [
                  "Blue",
                  "Blue"
              ]
          ],
          "n" : [
              [
                  {
                      "$minElement" : 1
                  },
                  {
                      "$maxElement" : 1
                  }
              ]
          ],
          "_id" : [
              [
                  {
                      "$minElement" : 1
                  },
                  {
                      "$maxElement" : 1
                  }
              ]
          ]
      }
  }
  </code></pre>
  
  <p>I've already figured out that the ordering of the keys in the index matter somehow. For instance if I used {_id, n:1, st:1} it wasn't using this index at all to perform the query. I also read somewhere that too few documents could trigger unpredictable behaviour with explain() since multiple strategies are equally fast. But in this case, I see that its using the right index, but its not using just the index. What is this happening?</p>
  
  <p>I am using mongoid, and mongo 2.0.8 I believe.</p>
  
  <p>UPDATE:</p>
  
  <p>Switched over to using Mongoid v3.1.4 and mongod v2.2</p>
  
  <p>Here is the query that mongod is seeing from mongoid: Mon Jul 15 10:47:26 [conn14] runQuery called spl_development.merchants { $query: { st: { $regex: "cr", $options: "i" } }, $explain: true } Mon Jul 15 10:47:26 [conn14] query spl_development.merchants query: { $query: { st: { $regex: "cr", $options: "i" } }, $explain: true } ntoreturn:0 keyUpdates:0 locks(micros) r:212 nreturned:1 reslen:393 0ms</p>
  
  <p>So the projection isn't being sent to the mongod layer and only just handles it in the application layer. Not ideal!</p>
  
  <p>This has been recognized as a bug in mongoid and can be tracked here:
  <a href="https://github.com/mongoid/mongoid/issues/3142" rel="nofollow">https://github.com/mongoid/mongoid/issues/3142</a></p>