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"
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.