Я построил это агрегирование:
ProjectionOperation projectStage = Aggregation
.project("application", "uploadedRefs", "uploadedKb", "downloadedDocs", "downloadedKb")
.and(DateOperators.Year.yearOf("timestamp")).as("year")
.and(DateOperators.Month.monthOf("timestamp")).as("month")
.and(DateOperators.DayOfMonth.dayOfMonth("timestamp")).as("day")
.and(DateOperators.DateFromParts.dateFromParts()
.yearOf("timestamp")
.monthOf("timestamp")
.dayOf("timestamp")
).as("startIntervalTimestamp");
Aggregation aggregation = Aggregation
.newAggregation(
projectStage
);
System.out.println(aggregation.toString());
Вывод:
[
{
"$project":{
"application":1,
"uploadedRefs":1,
"uploadedKb":1,
"downloadedDocs":1,
"downloadedKb":1,
"year":{
"$year":"$timestamp"
},
"month":{
"$month":"$timestamp"
},
"day":{
"$dayOfMonth":"$timestamp"
},
"startIntervalTimestamp":{
"$dateFromParts":{
"year":"timestamp",
"month":"timestamp",
"day":"timestamp"
}
}
}
}
]
Сообщение об ошибке:
Error: command failed: {
"ok" : 0,
"errmsg" : "'year' must evaluate to an integer, found string with value \"timestamp\"",
"code" : 40515,
"codeName" : "Location40515"
}