spring-projects / spring-projects/spring-data-mongodb
ReactiveStringBasedAggregation computes pipeline stages with domainClass instead of return type
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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