ListOperations=new ArrayList (a);
Operations. The add (
Aggregation. Project (). AndExpression (" substr (startTime, 0, 10) "), the as (" day ")
);
Operations. The add (
Aggregation. Group (" day ")
Sum (" $duration "). The as (" totalDuration ")
);
Operations. The add (
Aggregation. The match (
The Criteria. The where (" : ") is (ccId)
And (" startTime "). Gte (dateFrom). Lte (dateTo)
)
);
Operations. The add (
Aggregation. Sort (sort. Direction. ASC, "_id")//ascending sort by date
);
Aggregation Aggregation=Aggregation. NewAggregation (operations);
AggregationResultsResults=mongoTemplate. Aggregate (
Aggregation, "t_call_record", BasicDBObject class);
ListMappedResults=the getMappedResults ();
Breakpoint debugging, implementation to
AggregationResultsResults=mongoTemplate. Aggregate (
Aggregation, "t_call_record", BasicDBObject class);
Code error, tip:
Java. Lang. IllegalArgumentException: Invalid reference '$duration!
"Duration" is a collection of a key in the mongo, business requirements is daily statistical duration key corresponding to the value of the cumulative values,
I will Aggregation in another business method. The project () and Aggregation. The group (" day "). The count () as (" totalCnt ") is used to statistical number no error, thought is the same Aggregation rows, the sum () and usage of the count () should be the same, after I made several attempts to find if you remove
Operations. The add (
Aggregation. Group (" day ")
Sum (" $duration "). The as (" totalDuration ")
);
This code, the error will not quote, but also do not accord with my business logic,
So I want to ask you a great god, and used in springboot mongoTemplate mongo's interactive operation, related grammar to Aggregation. The project () and Aggregation. The group (). The sum () is used in combination, are there any other restrictions or grammar? Thank you very much!
CodePudding user response:
Under the roof to yourself and don't sink so quicklyCodePudding user response:
O $duration represents a variableDirectly with duration
CodePudding user response:
Operations. The add (Aggregation. project (" duration ") . AndExpression (" substr (startTime, 0, 10) "), the as (" day ")
);
Operations. The add (
Aggregation. Group (" day ")
. the sum (" duration "). the as (" totalDuration ")
);