title: node.js mongodb driver and mongoose: multiple limits possible?
body: <p>Can I limit the amount of find-results several times?</p>
  
  <p>The reason being that I am adding now a sort option to the results of an existing application. I am already limiting the result set for pagination, but if I additionally sort, first the whole result would have to be sorted and then the result skipped/limited.</p>
  
  <p>I don't care about 100% accurate results, but don't want to make the db too busy. So what I am trying is:</p>
  
  <pre><code>MyCollection.find(pattern).limit(somelargenumber).sort({score:desc}).skip(0).limit(10);
  </code></pre>
  
  <p>and that both for mongoose and the native mongodb driver.</p>
  
  <p>Is that even possible? And.. does it make any sense?</p>
  
  <p>(I would normally expect amount of documents returned for each query to be &lt;100, but if someone somehow selects all documents, I want to prevent bad response time, and inaccurate results are ok for that case.)</p>
  
  <p>Actually, from a quick test, I could not come up with a javascript query in the mongo command line - though it should be possible with the aggregation framework I think..</p>
  
  <pre><code> db.books.find().limit(1).sort({weightedRating:-1}).limit(10);
  </code></pre>
  
  <p>returns (as far as I can see) too many books (more than 1) and also the book has a great weightedRating, like not any random book would have (which should have been achieved by the first limit(1)).</p>