Mongodb get data using ISO format date -


i saving data mongodb , dates in format instance

7/30/1960 (july 30, 1960) isodate("1960-07-30t05:00:00.000+0000"),

i want find records created today(and dont care time,so long today) , have this

var start = new date(); var end = new date(); 

and display data

db.posts.find({created_on: {$gte: start, $lt: end}}); 

will work or must convert iso dates format first?.

you can alter 'start' , 'end' variables before querying:

var start = new date(); start.sethours(0,0,0,0); // remove time part date  var end = new date(); end.sethours(0,0,0,0); // remove time end.setdate(end.getdate() + 1); // add day end date 

and can use query:

db.posts.find({created_on: {$gte: start, $lt: end}}); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -