Java 错误:无法解析符号';日期运算符';-MongoTemplate
我想将下面的代码添加到我的项目中Java 错误:无法解析符号';日期运算符';-MongoTemplate,java,spring,mongodb,Java,Spring,Mongodb,我想将下面的代码添加到我的项目中 Aggregation aggregation = newAggregation( project(from(field("dayActivity.type", "dayActivity.type"), field("tid"))). and(DateOperators.dateOf("activityDat
Aggregation aggregation = newAggregation(
project(from(field("dayActivity.type", "dayActivity.type"),
field("tid"))).
and(DateOperators.dateOf("activityDate").toString("%Y-%m-%d")).as("yearMonthDay"),
match(where("yearMonthDay").is("2017-11-05").and("tid").is("12345678"))
);
我甚至不能在我的项目中添加DateOperators.class或特定的maven依赖项。
它显示了一个错误
导入时:
import org.springframework.data.mongodb.core.aggregation.DateOperators;
错误:无法解析符号“DateOperators”
--使用4.0.5 MongoDB版本
如何继续?要将
日期
字段投影为格式字符串%Y-%m-%d”
请使用以下语法:
project()
.and(DateOperators.DateToString
.dateOf("activityDate")
.toString("%Y-%m-%d"))
.as("yearMonthDay")
而且,您希望导入org.springframework.data.mongodb.core.aggregation.DateOperators
。这在Spring数据MongoDB 2.3和MongoDB服务器v4.2上运行良好
例如,日期字段
activityDate
的值为ISODate(“2020-09-23T12:10:15.710Z”)
被投影为一个名为yearMonthDay
的字段,该字段的值为“2020-09-23”
注:聚合操作符dateToString
是在MongoDB v3.0中引入的。