title: Indexing MongoDB for quicker find() with sort(), on different fields
body: <p>I'm running lots of queries of such type:</p>
  
  <pre><code>db.mycollection.find({a:{$gt:10,$lt:100}, b:4}).sort({c:-1, a:-1})
  </code></pre>
  
  <p>What sort of index should I use to speed it up? I think I'll need to have both <code>{a:1, b:1}</code> and <code>{c:-1, a:-1}</code>, am I right? Or these indexes will somehow interfere with each other at no performance gain?</p>
  
  <p>EDIT: The actual problem for me is that I run many queries in a loop, some of them over small range, others over large range. If I put index on <code>{a:1, b:1}</code>, it selects small chunks very quickly, but when it comes to large range I see an error "too much data for sort() with no index". If, otherwise, I put index on <code>{c:-1, a:-1}</code>, there is no error, but the smaller chunks (and there are more of those) are processed much slower. So, how is it possible to keep the quickness of selection for smaller ranges, but not get error on large amount of data?</p>
  
  <p>If it matters, I run queries through Python's pymongo.</p>