How to sort a client-side-only (local) Meteor Collection

meteor

Solution

It works for me, are you using the latest version of Meteor? Running this code works on the Meteor Docs site:

var foos = new Meteor.Collection( null );
for ( var i = 0; i < 100; i++ ) {
  foos.insert({ num: i });
}
foos.findOne( {} ).num; // => 0
foos.findOne( {}, { sort: [[ "num", "desc" ]] } ).num; // => 99

Problem

I have client side only (local) Meteor collection defined like that (coffeescript): Products = new Meteor.Collection null However when I try to find() providing sorting parameters Meteor tells me that sorting of local collections is not supported. This is understandable. I would like to know what is the easiest/simplest way to get sorted results. Essentially I always use all the data in the Collection, so keeping it in sorted state would solve the problem.

Original source