Skip to content

Instantly share code, notes, and snippets.

@tairov
Created April 16, 2013 06:33
Show Gist options
  • Save tairov/5393819 to your computer and use it in GitHub Desktop.
Save tairov/5393819 to your computer and use it in GitHub Desktop.
var current_id; // id of first record on current page.
// go to page current+N
db.collection.find({_id: {$gt: current_id}}).
skip(N * page_size).
limit(page_size).
sort({_id: 1});
// go to page current-N
db.collection.find({_id: {$lt: current_id}}).
skip((N-1)*page_size).
limit(page_size).
sort({_id: 1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment