MongoDB: How to do any consult with dates ?

First you need save in date format in your MongoDB.

Example:

var dtStart = new Date(moment(dts).format("MM/DD/YYYY HH:MM"));
var dtEnd = new Date(moment(dte).format("MM/DD/YYYY HH:MM"));

var period = {
    dt_start:dtStart,
    dt_end:dtEnd
};

Use

'mydate':{$gte:dtStart,$lte:dtEnd}}

Example :

return Events.find({places: { $exists: true },places:{$in:idPlaces},category:category,'sessions.dt_start': { $exists: true },'sessions.dt_start':{$gte:dtStart,$lte:dtEnd}},{sort:{createdAt: -1}});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s