O'Reilly logo

Meteor: Full-Stack Web Application Development by Marcelo Reyna, Isaac Strack, Fabian Vogelsteller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sorting with MongoDB queries

There are many times when you will need to sort a collection. Most recent comments, alphabetized lists, and bank transactions by amount are all good examples. This recipe will show you how to sort MongoDB collections, using the options in your find() request.

Getting ready

We will be using the Implementing a simple collection recipe found in this chapter as a baseline. please follow that recipe in preparation for this activity.

How to do it…

To perform sorting with MongoDB queries, proceed with the following steps:

  1. In your main.html file (located at [project root]/client/main.html), make the following modification to the {{#each…}} template fragment:
    {{#each comments}}
      <div>{{text}}{{number}}</div> {{/each}} {{greeting}} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required