Mongoose find n records after specific record Mongoose find n records after specific record mongoose mongoose

Mongoose find n records after specific record


Simply sort the cursor by _id and limit the result to n

db.collection.find({'_id': {'$gt': record_id } }).sort({'_id': 1}).limit(n)


ObjectId contains a timestamp with millisecond precision, so chance of having same timestamp for two objects is near zero!

In order to sort by ObjectId you can use this post.