Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor client side sort Collection

I have a DrawingHistory collection which stores data to be used for redrawing canvas data, but I can't seem to find a way to sort the information by a time property. Here's my current function

DrawingHistory.find().observeChanges
  added: ( id , data ) =>
    @setupUserDraw data unless Session.equals 'user_id' , data.sid

Sometimes the order gets messed up, and I looked online for sorting where people say to do DrawingHistory.find().sort( { time: -1 } ) but find() doesn't have a sort property. Any ideas where I'm off?

like image 881
Marius Miliunas Avatar asked Jun 08 '26 02:06

Marius Miliunas


1 Answers

If my memory isn't failing me, this should do it, the first {} being the selector, the second {...} being the options.

DrawingHistory.find({}, {sort: {time: -1}});

EDIT: Found the docs on find().

like image 87
Joachim Isaksson Avatar answered Jun 10 '26 20:06

Joachim Isaksson