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

Filtering with MongoDB queries

Whether you're performing searches, organizing records, or narrowing down results, sooner or later, you'll want to filter the results of your collections. This recipe shows you how to limit the number of records in a collection, using MongoDB's find method options.

Getting ready

We will use the project created in the Sorting with MongoDB queries recipe, found in this chapter. Please complete that recipe, and use the files as a baseline for this recipe.

How to do it…

To filter MongoDB queries, proceed with the following steps:

  1. Make the following change to the comments helper function in [project root]/client/scripts/main.js:
    Template.hello.helpers({
      ...
      comments: function () {
        return Comments.find({number:/[2468]/},{sort:{number:-1}} ...

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