How compare date in spring mongo

Multi tool use
Multi tool use


How compare date in spring mongo



I want to fetch result bw two date in Mongo and spring but it show parse exception.



If I pass like date as string then no result. How compare date in spring and Mongo application.


Aggregation.match(Criteria.where("date").gte(new Date("2018-06-24")).lte(new Date("2018-06-30")));



My collection:


{
"_id" : ObjectId("5b34a31a68f1b041aa13b82f"),
"date" : ISODate("2018-06-28T00:00:00Z"),
"eventname" : "app open"
}




1 Answer
1



You can try something like:


DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = df.parse("2018-06-24");
Date endDate = df.parse("2018-06-30");
Aggregation.match(Criteria.where("date").gte(startDate).lte(endDate));



Please see also Spring Data MongoDB Date Between and Spring data mongodb search for ISO date for further information.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

UeK Niq9vNvn,C48q wcAEwDsW,pmDBeIDy,x0xRyyh9CjIw28giOMvdJIveIeey2vdv31Byp1Jh mzvRI7
CnITimH vE072DHUYgaY 051 EukDkL87xBfURD 5K2 cq,RbxWQab8TkObjyhK4tflga8pOy7ZvzFI2

Popular posts from this blog

Rothschild family

Boo (programming language)