Skip to content

TypeBasedAggregationOperationContext.getReferenceFor(…) exposes fields with their leaf property name [DATAMONGO-1586] #2498

Closed
@spring-projects-issues

Description

@spring-projects-issues

Romuald Coeffier opened DATAMONGO-1586 and commented

Try to use project operation to rename fields and it does not work on root fields.

Document before project operation:

{
  "foo": "v1",
  "fooSub": {
    "sub": "v2"  
  } 
}

Expected result after project:

{
  "bar": "v1",
  "sub": "v2"
}

But get result:

{
  "bar": "null,
  "sub": "v2"
}

Test:

        Foo foo = new Foo("v1", new FooSub("v2"));
        ops.save(foo);

        Aggregation aggregation = Aggregation.newAggregation(
            project()
                .and("foo").as("bar")
                .and("fooSub.sub").as("sub"));
        List<Bar> mappedResults = ops.aggregate(aggregation, Foo.class, Bar.class).getMappedResults();

        assertThat(mappedResults.size()).isEqualTo(1);
        assertThat(mappedResults.get(0).getSub()).isEqualTo("v2"); // ok
        assertThat(mappedResults.get(0).getBar()).isEqualTo("v1"); // failed getBar() returns null instead of "v1"

In debug, Aggregation object is ok:

{ "aggregate" : "__collection__" , "pipeline" : [ { "$project" : { "bar" : "$foo" , "sub" : "$fooSub.sub"}}]}

but after convert to DBObject, $project part contains:

  • "bar" -> "1"
  • "sub" -> "$fooSub.sub"

Affects: 1.7.3 (Fowler SR3), 1.8.6 (Gosling SR6), 1.9.6 (Hopper SR6)

Referenced from: pull request #434, and commits c2bfe42, 174f7f0, 6c6ac6d, 76d6c14, 8df9d30

Backported to: 1.10 GA (Ingalls), 1.9.7 (Hopper SR7)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions