title: Retrieving next N records in mongo db
body: <p>I need a scheduler job which will execute every 5 mins and process next 100 records from a mongodb collection. It should start from the document which was inserted first. So, in the first run, i can sort the data in ascending order and get the first 100 documents. But for the consecutive runs, how can i retrieve the next 100 records giving the last processed document's object id? (i'm not sure how to use the object id here as it is a generating string with different parameters... i don't have any other id defined.)</p>
  
  <p>If this is not a good way to retrieve records from mongodb for a large data set, please suggest a better way.</p>
  
  <p>Each document looks like below:</p>
  
  <pre><code>{ "_id" : { "$oid" : "51ff17c8e4b02969f18e72bb"} , "source_of_info" : "somesource" , 
  "entityinfo" : [ { "user" : "Alfredo Vela Zancada" , "social_network_entity_id" : 
   364221775325822977 , "text" : "blah blah blah" , "created_at" : { "$date" : "2013-08-
   05T03:10:12.000Z"}}] , "relatedURLs" : [ { "url" : "http://t.co/swqP3FYQt5" 
   ,"expanded_url" : "http://ow.ly/nCkIS"}]}
  </code></pre>
  
  <p>Thanks.</p>