I am trying to get the previous and next item in a collection. Below is what I have tried, but it is not working. I get results, but they are not returning in the correct order. Any suggestions?
Previous:
Meteor.videos.find({$lt: currentID}, {sort: {date: -1}, limit:1});
Next:
Meteor.videos.find({$gt: currentID}, {sort: {date: -1}, limit:1});
Try querying on the date, rather than document ID.
var current = Meteor.videos.findOne(currentID);
Previous:
Meteor.videos.find({date: {$lt: current.date}}, {sort: {date: -1}, limit:1});
Next:
Meteor.videos.find({date: {$gt: current.date}}, {sort: {date: 1}, limit:1});
You also need to sort the next cursor in ascending order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With