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.

Raw
var now = new Date();
yourModel.find({timestamp: {$lte: now}}).exec(...);

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.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceTorWorldInternet securityFontGnuPGThunderbirdJenkins