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
46ea58f3b9
commit
cec6526543
@@ -455,7 +455,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (value instanceof AggregationExpression) {
|
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, getRequiredName()), null));
|
return this.operation.and(new FieldProjection(Fields.field(alias, getRequiredName()), null));
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import org.junit.rules.ExpectedException;
|
|||||||
import org.springframework.data.domain.Sort.Direction;
|
import org.springframework.data.domain.Sort.Direction;
|
||||||
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
|
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.test.util.BasicDbListBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link Aggregation}.
|
* Unit tests for {@link Aggregation}.
|
||||||
@@ -569,6 +568,23 @@ public class AggregationUnitTests {
|
|||||||
is(equalTo(new Document("val", new Document("$add", Arrays.asList("$value1.value", "$value2.value"))))));
|
is(equalTo(new Document("val", new Document("$add", Arrays.asList("$value1.value", "$value2.value"))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAMONGO-1871
|
||||||
|
public void providedAliasShouldAllowNestingExpressionWithAliasCorrectly() {
|
||||||
|
|
||||||
|
Document condition = new Document("$and",
|
||||||
|
Arrays.asList(new Document("$gte", Arrays.asList("$$est.dt", "2015-12-29")), //
|
||||||
|
new Document("$lte", Arrays.asList("$$est.dt", "2017-12-29")) //
|
||||||
|
));
|
||||||
|
|
||||||
|
Aggregation agg = newAggregation(project("_id", "dId", "aId", "cty", "cat", "plts.plt")
|
||||||
|
.and(ArrayOperators.arrayOf("plts.ests").filter().as("est").by(condition)).as("plts.ests"));
|
||||||
|
|
||||||
|
Document $project = extractPipelineElement(agg.toDocument("collection-1", Aggregation.DEFAULT_CONTEXT), 0,
|
||||||
|
"$project");
|
||||||
|
|
||||||
|
assertThat($project.containsKey("plts.ests"), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
private Document extractPipelineElement(Document agg, int index, String operation) {
|
private Document extractPipelineElement(Document agg, int index, String operation) {
|
||||||
|
|
||||||
List<Document> pipeline = (List<Document>) agg.get("pipeline");
|
List<Document> pipeline = (List<Document>) agg.get("pipeline");
|
||||||
|
|||||||
Reference in New Issue
Block a user