[英]How to build a Spring Query in Mongo DB with a criteria considering two string date range
[英]How compare date in spring mongo
我想在Mongo和Spring中獲取兩個日期的結果,但是它顯示了parse異常。
如果我將日期作為字符串傳遞,則沒有結果。 如何在Spring和Mongo應用程序中比較日期。
Aggregation.match(Criteria.where("date").gte(new Date("2018-06-24")).lte(new Date("2018-06-30")));
我的收藏:
{
"_id" : ObjectId("5b34a31a68f1b041aa13b82f"),
"date" : ISODate("2018-06-28T00:00:00Z"),
"eventname" : "app open"
}
您可以嘗試如下操作:
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));
另請參閱Spring Data MongoDB日期之間和Spring data mongodb搜索ISO日期以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.