spring-projects / spring-projects/spring-data-mongodb

ReactiveStringBasedAggregation computes pipeline stages with domainClass instead of return type

Open
#3,532 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: pending-design-work
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Currently the #computePipelineStage(String, ConvertingParameterAccessor, ParameterBindingDocumentCodec) method in the ReactiveStringBasedAggregation class maps the pipeline operation sources to the domain class, resulting in fields in a $project stage being incorrectly being resolved as _id as its name in the expected return type (Bar) -> namely identifier

Consider the following repository with an aggretion query, and 2 data models;

@Repository
interface FooRepository extends ReactiveMongoRepository<Foo, String> {

    @Aggregation(pipeline = {
            "{ $match : { _id : '?0' } }",
            "{ $replaceRoot : { newRoot : '$bar' } }",
            "{ $project : { identifier : 1 } }"
    })
    Mono<Bar> findBarBy(String identifier);
}

@Getter
@Setter
@Document
class Foo {

    @Id private String identifier;
    private Bar bar;
}

@Getter
@Setter
@Document
class Bar {

    private String identifier;
}

Executing the aggregation results in an instance of Bar , however the identifier is null , due the fact that the ReactiveStringBasedAggregation maps the pipeline stages to the domain class and identifier is being transformed to _id

Added a sample project -> https://github.com/dnijssen/mongodb-aggregation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ReactiveStringBasedAggregation at #computePipelineStage(String, ConvertingParameterAccessor, ParameterBindingDocumentCodec) and compare how pipeline sources are mapped to the domain class versus the aggregation return type. Use the linked sample project to reproduce the Foo-to-Bar query, then verify that the $project identifier is retained as identifier rather than resolved to _id.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.