title: MongoDB find has the same speed with and without index
body: <p>I use MongoTemplate from Spring to access a MongoDB.</p>
  
  <pre><code>final Query query = new Query(Criteria.where("_id").exists(true));
  query.with(new Sort(Direction.ASC, "FIRSTNAME", "LASTNAME", "EMAIL"));
  if (count &gt; 0) {
      query.limit(count);
  }
  query.skip(start);
  query.fields().include("FIRSTNAME");
  query.fields().include("LASTNAME");
  query.fields().include("EMAIL");
  return mongoTemplate.find(query, User.class, "users");
  </code></pre>
  
  <p>I generated 400.000 records in my MongoDB.
  When asking for the first 25 Users without using the above written sort line, I get the result within less then 50 milliseconds.</p>
  
  <p>With sort it lasts over 4 seconds.</p>
  
  <p>I then created indexes for FIRSTNAME, LASTNAME, EMAIL. Single indexes, not combined ones</p>
  
  <pre><code>mongoTemplate.indexOps("users").ensureIndex(new Index("FIRSTNAME", Order.ASCENDING));
  mongoTemplate.indexOps("users").ensureIndex(new Index("LASTNAME", Order.ASCENDING));
  mongoTemplate.indexOps("users").ensureIndex(new Index("EMAIL", Order.ASCENDING));
  </code></pre>
  
  <p>After creating these indexes the query again lasts over 4 seconds.</p>
  
  <p>What was my mistake?</p>
  
  <p>-- edit
  MongoDB writes this on the console...</p>
  
  <pre><code>Thu Jul 04 10:10:11.442 [conn50] query mydb.users query: { query: { _id: { $exists: true } }, orderby: { LASTNAME: 1, FIRSTNAME: 1, EMAIL: 1 } } ntoreturn:25 ntoskip:0 nscanned:382424 scanAndOrder:1 keyUpdates:0 numYields: 2 locks(micros) r:6903475 nreturned:25 reslen:3669 4097ms
  </code></pre>