Sorting collections in Meteor.js

I was surprised to find that it was trickier than I expected to find a good example of sorting my collection queries in meteor.js. It’s not hard, but the syntax was different than most of the MongoDB examples I was looking at. Here’s a sample format:

Template.myTemplate.gizmos = function () {
  return Gizmos.find({}, {sort: [[ name: "asc" ]]});
};

You can also accomplish the same thing like so:

Template.myTemplate.gizmos = function () {
  return Gizmos.find({}, {sort: { name: 1 }});
};

Comments are closed.