Any mongoose and mongo experts out there that can help me out? As the title says I wanna try and implement cursor based pagination. I've seen an old post here about it but I'm trying to see how I can get the second set of posts.
I get this part
const items = db.items.find({}).sort({
_id: -1
}).limit(2);
const next = items[items.length - 1]._id
res.json({ items, next })
But how do i apply this second part. Am i suppose to create a separate route for this?
const items = db.items.find({
_id: { $lt: req.query.next }
}).sort({
_id: -1
}).limit(2);
const next = items[items.length - 1]._id
res.json({ items, next })