title: Why mongodb sort by _id is much faster than sort by any other indexed field?
body: <p>I'm trying to fully sort a collection with millions of rows by a single field.
  As far i know, ObjectId contains 4 bytes of timestamp. And my timestamp  is 4 bytes integer indexed field. So i suppose sort by _id and timestamp should be simular, but here's results</p>
  
  <pre><code>db.coll.find().sort("_id", pymongo.ASCENDING)
  # takes 25 minutes to run
  </code></pre>
  
  <p>and</p>
  
  <pre><code>db.coll.find().sort("timestamp", pymongo.ASCENDING)
  # takes 2 hours to run
  </code></pre>
  
  <p>why is this happening, and is here the way to optimize that?
  Thanks</p>
  
  <p>UPDATE</p>
  
  <p>The timestamp field i'm trying to sort with is already indexed as i pointed</p>
  
  <p>collection stats</p>
  
  <pre><code>"size" : 55881082188,
  "count" : 126048972,
  "avgObjSize" : 443,
  "storageSize" : 16998031360,
  "capped" : false,
  "nindexes" : 2,
  "totalIndexSize" : 2439606272,
  </code></pre>
  
  <p>and I dedicated to mongodb proccess 4gb of ram (tried to increase to 8gb but speed didn't increased)</p>
  
  <p>UPDATE 2</p>
  
  <p>It's turned out how much sorting on field order follows insertion (natural) order, so much the sorting speed is faster</p>
  
  <p>I tried to</p>
  
  <pre><code>db.new_coll.create_index([("timestamp", pymongo.ASCENDING)])
  for el in db.coll.find().sort("timestamp", pymongo.ASCENDING):
      del el['_id']
      db.new_coll.insert(el)
  
  # and now
  db.new_coll.find().sort("timestamp", pymongo.ASCENDING)
  # takes 25 minutes vs 2 hours as in previous example
  </code></pre>