|
32 | 32 | import org.junit.Test;
|
33 | 33 | import org.springframework.data.domain.Range;
|
34 | 34 | import org.springframework.data.mongodb.core.DocumentTestUtils;
|
| 35 | +import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce; |
35 | 36 | import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.PropertyExpression;
|
36 | 37 | import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.Variable;
|
| 38 | +import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Slice; |
37 | 39 | import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Switch.CaseOperator;
|
38 | 40 | import org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder;
|
| 41 | +import org.springframework.data.mongodb.core.aggregation.StringOperators.Concat; |
39 | 42 | import org.springframework.data.mongodb.core.aggregation.VariableOperators.Let.ExpressionVariable;
|
40 | 43 |
|
41 | 44 | /**
|
@@ -1573,6 +1576,27 @@ public void shouldRenderReduceWithComplexObjectCorrectly() {
|
1573 | 1576 | "{ $project : { \"results\": { $reduce: { input: \"$probabilityArr\", initialValue: { \"sum\" : 5 , \"product\" : 2} , in: { \"sum\": { $add : [\"$$value.sum\", \"$$this\"] }, \"product\": { $multiply: [ \"$$value.product\", \"$$this\" ] } } } } } }")));
|
1574 | 1577 | }
|
1575 | 1578 |
|
| 1579 | + @Test // DATAMONGO-1843 |
| 1580 | + public void shouldRenderReduceWithInputAndInExpressionsCorrectly() { |
| 1581 | + |
| 1582 | + Document exprected = Document.parse( |
| 1583 | + "{ \"$project\" : { \"results\" : { \"$reduce\" : { \"input\" : { \"$slice\" : [\"$array\", 5] }, \"initialValue\" : \"\", \"in\" : { \"$concat\" : [\"$$value\", \"/\", \"$$this\"] } } } } }"); |
| 1584 | + |
| 1585 | + Reduce reduceEntryPoint = Reduce.arrayOf(Slice.sliceArrayOf("array").itemCount(5)) // |
| 1586 | + .withInitialValue("") // |
| 1587 | + .reduce(Concat.valueOf("$$value").concat("/").concatValueOf("$$this")); |
| 1588 | + |
| 1589 | + Reduce arrayEntryPoint = ArrayOperators.arrayOf(Slice.sliceArrayOf("array").itemCount(5)) // |
| 1590 | + .reduce(Concat.valueOf("$$value").concat("/").concatValueOf("$$this")) // |
| 1591 | + .startingWith(""); |
| 1592 | + |
| 1593 | + assertThat(project().and(reduceEntryPoint).as("results").toDocument(Aggregation.DEFAULT_CONTEXT), |
| 1594 | + Matchers.is(exprected)); |
| 1595 | + |
| 1596 | + assertThat(project().and(arrayEntryPoint).as("results").toDocument(Aggregation.DEFAULT_CONTEXT), |
| 1597 | + Matchers.is(exprected)); |
| 1598 | + } |
| 1599 | + |
1576 | 1600 | @Test // DATAMONGO-1548
|
1577 | 1601 | public void shouldRenderZipCorrectly() {
|
1578 | 1602 |
|
|
0 commit comments