Closed
Description
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)