|
29 | 29 | import org.junit.jupiter.api.Test;
|
30 | 30 | import org.springframework.data.domain.Sort.Direction;
|
31 | 31 | import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
|
| 32 | +import org.springframework.data.mongodb.core.aggregation.ProjectionOperationUnitTests.BookWithFieldAnnotation; |
| 33 | +import org.springframework.data.mongodb.core.convert.MappingMongoConverter; |
| 34 | +import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver; |
| 35 | +import org.springframework.data.mongodb.core.convert.QueryMapper; |
| 36 | +import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
32 | 37 | import org.springframework.data.mongodb.core.query.Criteria;
|
33 | 38 |
|
34 | 39 | /**
|
@@ -582,6 +587,17 @@ void shouldAllowInternalThisAndValueReferences() {
|
582 | 587 | "{\"attributeRecordArrays\": {\"$reduce\": {\"input\": \"$attributeRecordArrays\", \"initialValue\": [], \"in\": {\"$concatArrays\": [\"$$value\", \"$$this\"]}}}}"));
|
583 | 588 | }
|
584 | 589 |
|
| 590 | + @Test // DATAMONGO-2644 |
| 591 | + void projectOnIdIsAlwaysValid() { |
| 592 | + |
| 593 | + MongoMappingContext mappingContext = new MongoMappingContext(); |
| 594 | + Document target = new Aggregation(bucket("start"), project("_id")).toDocument("collection-1", |
| 595 | + new RelaxedTypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext, |
| 596 | + new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext)))); |
| 597 | + |
| 598 | + assertThat(extractPipelineElement(target, 1, "$project")).isEqualTo(Document.parse(" { \"_id\" : \"$_id\" }")); |
| 599 | + } |
| 600 | + |
585 | 601 | private Document extractPipelineElement(Document agg, int index, String operation) {
|
586 | 602 |
|
587 | 603 | List<Document> pipeline = (List<Document>) agg.get("pipeline");
|
|
0 commit comments