node.js - Mongodb: How to get records N to M? -
lets want records 5 10 (second last 5 records).
what query should used in nodejs or mongodb shell ?
i know last 5 messages 1 try (in nodejs):
db.collection(collection_name).find().limit(5);
as @saleem posted in comments, need .skip()
db.coll.find(querydoc).skip(x).limit(y)
however, have predictable order, should add .sort()
db.coll.find(querydoc).sort(sortdoc).skip(x).limit(y)
Comments
Post a Comment