jquery - MongoDB (Java driver) - Query date in interval -


i'm new mongodb , trying make query java driver records within date interval.

in shell when :

db.messages.find({     "date" : {         $gt: isodate("2014-01-01t00:00:00z"),         $lt: isodate("2014-01-01t00:00:05z")     } }); 

it returns 4 records.

in java i'm doing this:

try {      simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");      date d1 = dateformat.parse("2014-01-01 00:00:00");     date d2 = dateformat.parse("2014-01-01 00:00:05");      basicdbobject query = new basicdbobject();     query.append("date", new basicdbobject().append("$gte", d1).append("$lt", d2));      system.out.println(query); } catch (parseexception ex) { logger.getlogger(mongodbnavigationmessagedao.class.getname()).log(level.severe, null, ex); } 

if search query, no record. moreover, output of system.out.println(query); :

{ "date" : { "$gte" : { "$date" : "2013-12-31t23:00:00.000z"} , "$lt" : { "$date" : "2013-12-31t23:00:05.000z"}}} 

as can see, dates wrong... what's going on??

well found it, printed date isn't same because mongodb taking timezone account. , had no result because of typo...


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -