javascript - Mongo date range query (GMT) -


i have 2 variables:

var start = 'sun, 17 aug 2014 04:00:00 gmt'; var end = 'mon, 18 aug 2014 04:00:00 gmt'; 

when try run query in mongodb command line :

 db.model.find({"utctime": {$gte: start, $lt: end}}) 

it not return data.

the documents are:

{ "__v" : 0, "_id" : objectid("53f1663cb07994e23738d96f"), "utctime" : isodate("2014-08-18t02:34:21.225z")} { "__v" : 0, "_id" : objectid("53f1646ef2ab609325414462"), "utctime" : isodate("2014-08-17t23:06:21.364z")} { "__v" : 0, "_id" : objectid("53f163c6f2ab609325414461"), "utctime" : isodate("2014-08-17t23:06:21.364z")} { "__v" : 0, "_id" : objectid("53f1066a790f5f3d11a42a4b"), "utctime" : isodate("2014-08-17t19:45:19.669z")} { "__v" : 0, "_id" : objectid("53f0d9273af087e674e6f351"), "utctime" : isodate("2014-08-17t16:31:54.715z")} 

these "date" objects , not strings. use either javascript date object constructor or isodate helper create objects comparison. or otherwise same sort of object cnstructors in actual implementation language:

var start = new date( "2014-08-17" ); var end = new date( "2014-08-18" ); 

or hours , minutes important:

var start = new isodate("2014-08-17t04:00:00.000z"); var end = new isodate("2014-08-18t04:00:00.000z"); 

then queries work fine.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -