Meteor gathering gets the previous and next item

I am trying to get the previous and next items in a collection. Below I tried, but it does not work. I get the results, but they do not return in the correct order. Any suggestions?

Previous:

Meteor.videos.find({$lt: currentID}, {sort: {date: -1}, limit:1}); 

Further:

 Meteor.videos.find({$gt: currentID}, {sort: {date: -1}, limit:1}); 
+6
source share
1 answer

Try asking for a date, not a document id.

 var current = Meteor.videos.findOne(currentID); 

Previous:

 Meteor.videos.find({date: {$lt: current.date}}, {sort: {date: -1}, limit:1}); 

Further:

 Meteor.videos.find({date: {$gt: current.date}}, {sort: {date: 1}, limit:1}); 

You also need to sort the next cursor in ascending order.

+7
source

Source: https://habr.com/ru/post/973346/


All Articles