3

I have a problem with the project operation when using aggregation in Spring Data Mongo 1.3.2-RELEASE. The same operation works fine when I am using Spring Data Mongo 1.3.1-RELEASE:

At first I reduce my documents by projecting only two field and renaming them into x and y. Then I call a group operation on these two fields (x, y) including a count operation (with the name xPerY). After this grouping I want to project these two field which are now nested in the _id field in the not nested fields called x and y (without _id). As result I hope to get documents which only constists of xPerY, x and y. The following code worked fine for 1.3.1-RELEASE, but not for 1.3.2-RELEASE:

    AggregationOperation projectFirst = Aggregation.project( "x", "y" ).and( xField ).as( "x" ).and( yField ).as( "y" );
    AggregationOperation group = Aggregation.group( "x", "y" ).count( ).as( "xPerY" );
    AggregationOperation project = Aggregation.project( "xPerY", "x", "y" ).andExclude( "_id" );

    aggregation = Aggregation.newAggregation( projectFirst, group, project );

In 1.3.2-RELEASE the fields x and y will get the value 0 after the aggregation.

The AggregationOperation project in 1.3.2-RELEASE produces the following json: { "$project" : { "xPerY" : 1 , "x" : 1 , "y" : 1 , "_id" : 0}}

The AggregationOperation project in 1.3.1-RELEASE produces the following json: { "$project" : { "xPerY" : "$xPerY" , "x" : "$_id.x" , "y" : "$_id.y" , "_id" : 0}}

4

1 回答 1

1

I can confirm that this is a bug.

I filed an issue https://jira.springsource.org/browse/DATAMONGO-788 and added a pull request with a fix for it on github.

于 2013-10-29T12:30:59.200 回答