title: Paginating results in MongoDB without relying on .skip()
body: <p>I'm building an app that calls data from MongoDB. For purposes of this question, pretend that the user searches my app for a certain query, and MongoDB has 4,000 results to spit out that match the query.</p>
  
  <p>After reading around a bit, I see that it's possible to paginate using the <code>.skip()</code> method, <a href="http://docs.mongodb.org/manual/reference/method/cursor.skip/" rel="nofollow">but MongoDB themselves suggest against using this</a> as it requires the curser to iterate through all the records up until the one you're skipping to, which gets more and more expensive the higher in the list you go. </p>
  
  <p>I've seen a few tutorials that rely on the <code>_id</code> property of the results to be sequential, but this doesn't apply here - my database has tens of thousands of records, and each has a unique id, and the 4000 results that apply to the user's query are definitely not going to be sequential.</p>
  
  <p><strong>Can anyone think of a way to do this, or is <code>skip()</code> the only option here?</strong> </p>
  
  <p>Other considerations:</p>
  
  <p>The pagination will work based on the position on the page. For instance, the first query should spit out 20 records to my app. When the user scrolls to the bottom of the page, I could potentially get the <code>_id</code> of the 20th element on the page and pass that to my query, find it in the list of 4,000 results, find the subsequent result and start the next set of 20 from there. Is that sort of thing possible, and would it be less CPU intensive than <code>skip()</code>?</p>