Search code examples
mongodbmeteorminimongo

Meteor - Is it possible to query the database for items with a field that are equal or less than a value?


In my Meteor app my items in the database have a createdOn field with a date object as the value. I'd like to query for all items that were created on or before a certain date.

Is there a way to match on items with a value equal or less than a value I provide? Or do I need to return all items and then loop through them and pick out the ones I need?


Solution

  • Meteor uses mongodb as its database so you can just do this with the mongo operator $lt.

    For example:

    Posts.find({createdOn: {$lte: new Date()}});