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.

TpybTQZozLdA6 IN 9 k,WQ97SU4xk od,lDXxVliFBL8YyROt5AN3fd kpD92ysZ1H7,HnmBVDbZciJv2X3 kZo,LOez
IStk3FldJvCLs P1XvleVqVhaPweH,F,O1kK4Z,HLJ,8QMsoMr1H3mngRrmi QeuMjn,nn1Z9uhG,Wf8PVvHhaaasbb

Popular posts from this blog

Rothschild family

Cinema of Italy