1

I would like to sort a minimongo cursor using a date field. It appears that $orderBy will be deprecated according to the mongoDB documentation (not that I know if it works with minimongo) and sort() does not seem to work.

Is there a way to sort a minimongo cursor using a date field or should I rely on plain Javascript/underscore (Sorting by date with underscore.js or just plain JS)?

Community
  • 1
  • 1
Billybobbonnet
  • 3,156
  • 4
  • 23
  • 49

1 Answers1

0

It turns out that sort is supported, I just didn't get the syntax right. It would look like this:

myCollection.find({},{sort:{date:1}); // for older to newer items

Edit: more generally, 1 is for ascending and -1 is for descending. (for future readers, as noted by @BlazeSahlzen in comments)

Billybobbonnet
  • 3,156
  • 4
  • 23
  • 49