DATAMONGO-1871 - Fix AggregationExpression aliasing.
We now make sure to allow a nested property alias by setting the target. Original pull request: #533.
This commit is contained in:
committed by
Mark Paluch
parent
61b5977ada
commit
7275a10c1e
@@ -455,7 +455,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
}
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return this.operation.and(new ExpressionProjection(Fields.field(alias), (AggregationExpression) value));
|
||||
return this.operation.and(new ExpressionProjection(Fields.field(alias, alias), (AggregationExpression) value));
|
||||
}
|
||||
|
||||
return this.operation.and(new FieldProjection(Fields.field(alias, name), null));
|
||||
|
||||
@@ -574,6 +574,23 @@ public class AggregationUnitTests {
|
||||
new BasicDBObject("$add", new BasicDbListBuilder().add("$value1.value").add("$value2.value").get())))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1871
|
||||
public void providedAliasShouldAllowNestingExpressionWithAliasCorrectly() {
|
||||
|
||||
DBObject condition = new BasicDBObject("$and",
|
||||
Arrays.asList(new BasicDBObject("$gte", new BasicDbListBuilder().add("$$est.dt").add("2015-12-29").get()), //
|
||||
new BasicDBObject("$lte", new BasicDbListBuilder().add("$$est.dt").add("2017-12-29").get()) //
|
||||
));
|
||||
|
||||
Aggregation agg = newAggregation(project("_id", "dId", "aId", "cty", "cat", "plts.plt")
|
||||
.and(ArrayOperators.arrayOf("plts.ests").filter().as("est").by(condition)).as("plts.ests"));
|
||||
|
||||
DBObject $project = extractPipelineElement(agg.toDbObject("collection-1", Aggregation.DEFAULT_CONTEXT), 0,
|
||||
"$project");
|
||||
|
||||
assertThat($project.containsField("plts.ests"), is(true));
|
||||
}
|
||||
|
||||
private DBObject extractPipelineElement(DBObject agg, int index, String operation) {
|
||||
|
||||
List<DBObject> pipeline = (List<DBObject>) agg.get("pipeline");
|
||||
|
||||
Reference in New Issue
Block a user