Skip to content

Add support for nested field references in group operations [DATAMONGO-753] #1685

@spring-projects-issues

Description

@spring-projects-issues

Thomas Darimont opened DATAMONGO-753 and commented

use Spring Data (1.3.0.RC1) to access our MongoDB and for some new queries I want to use the aggregation framework.

In the mongo shell the command would be:

db.spotreports.aggregate(
{ "$unwind" : "$pd"} , { "$group" : { "_id" : "$pd.PDch", "base" : {$sum : "$pd.aBL"}, "uplift" : {$sum : "$pd.up"}}})
{
"result" : [
{
"_id" : 5,
"base" : 529133,
"uplift" : 21516
},
...
The Spring Code I use is:

Aggregation agg = Aggregation.newAggregation(
Aggregation.unwind("pd"),
Aggregation.group("pd.PDch").sum("pd.aBL").as("base").sum("pd.up").as("uplift")
);

AggregationResults<SpotReportResult> result = mongoTemplate.aggregate(agg, resolveCollection(), SpotReportResult.class);
I get the following error:

java.lang.IllegalArgumentException: Invalid reference 'PDch'!
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:63)
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:47)
at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:284)
at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:228)
I wonder why spring want to reference 'PDch' instead of 'pd.PDch'?


Affects: 1.3.1

Reference URL: http://stackoverflow.com/questions/18653574/spring-data-mongodb-aggregation-framework-invalid-reference-in-group-operati

Referenced from: commits fca8e74, f7460a6, fdb4781, b07e65f, 3d2ae81, 7eb0e6a, eeb74fb, 361f9da

Backported to: 1.3.2 (Babbage SR1)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions