I know that it is a bad practice to use skip
in order to implement pagination, because when your data gets large skip
starts to consume a lot of memory. One way to overcome this trouble is to use natural order by _id
field:
//Page 1
db.users.find().limit(pageSize);
//Find the id of the last document in this page
last_id = ...
//Page 2
users = db.users.find({'_id'> last_id}). limit(10);
The problem is - I'm new to mongo and do not know what is the best way to get this very last_id