Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation with $unwind and $project causes IllegalArgumentException #4714

Closed
shollander opened this issue Jun 3, 2024 · 1 comment
Closed
Assignees
Labels
type: bug A general bug

Comments

@shollander
Copy link

given the following data model:

@Document
public record TestRecord(@Id String field1, String field2, LayerOne layerOne) {
    public record LayerOne(List<LayerTwo> layerTwo) { }

    public record LayerTwo(LayerThree layerThree) { }

    public record LayerThree(int fieldA int fieldB) { }
}

The following aggregation query should work (and does work in the shell), but throws an error:

Aggregation agg = Aggregation.newAggregation(
    unwind("layerOne.layerTwo"),
    project().and("layerOne.layerTwo.layerThree").as("layerOne.layerThree"),
    sort(DESC, "layerOne.layerThree.fieldA")
    );
mongoTemplate.aggregate(agg, TestRecord.class, Document.class);

The following error is produced:

java.lang.IllegalArgumentException: Invalid reference: 'layerOne.layerThree.fieldA'
    at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:108)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 3, 2024
@christophstrobl
Copy link
Member

@shollander thank you for raising the issue. we'll have a look.

@christophstrobl christophstrobl self-assigned this Jun 11, 2024
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 11, 2024
@mp911de mp911de changed the title aggregation unwind/projection causes IllegalArgumentException: Invalid reference Aggregation with $unwind and $project causes IllegalArgumentException Jun 13, 2024
@mp911de mp911de added this to the 4.2.7 (2023.1.7) milestone Jun 13, 2024
mp911de pushed a commit that referenced this issue Jun 13, 2024
mp911de added a commit that referenced this issue Jun 13, 2024
Introduce FieldLookupPolicy and methods to create field-exposing/inheriting AggregationOperationContexts.

Move off RelaxedTypeBasedAggregationOperationContext.

See #4714
Original pull request: #4720
mp911de added a commit that referenced this issue Jun 13, 2024
Introduce FieldLookupPolicy and methods to create field-exposing/inheriting AggregationOperationContexts.

Move off RelaxedTypeBasedAggregationOperationContext.

See #4714
Original pull request: #4720
mp911de pushed a commit that referenced this issue Jun 13, 2024
mp911de added a commit that referenced this issue Jun 13, 2024
Introduce FieldLookupPolicy and methods to create field-exposing/inheriting AggregationOperationContexts.

Move off RelaxedTypeBasedAggregationOperationContext.

See #4714
Original pull request: #4720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
4 participants