Mongoose query by date

Looking at the code I'm really not sure how it could have taken me more than one minute to figure this out.. but here's an example how to query for documents with a timestamp in the past.

Your model's schema obviously needs a timestamp field of the Date type, and it's probably a good idea to set a default value.

var now = new Date();
yourModel.find({timestamp: {$lte: now}}).exec(...);
Published on Sept. 13, 2012 by Nicolas and tagged mongoose. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

1 comment

  1. avatar
    wrote this comment on
    Does this find things before now, after now, or right now?

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.