|
29 | 29 | import org.bson.Document;
|
30 | 30 | import org.junit.jupiter.api.Test;
|
31 | 31 | import org.springframework.data.annotation.Id;
|
| 32 | +import org.springframework.data.domain.Sort; |
32 | 33 | import org.springframework.data.domain.Sort.Direction;
|
33 | 34 | import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
|
34 | 35 | import org.springframework.data.mongodb.core.aggregation.ProjectionOperationUnitTests.BookWithFieldAnnotation;
|
@@ -629,6 +630,28 @@ void createsBasicAggregationOperationFromBson() {
|
629 | 630 | Document target = newAggregation(stage).toDocument("col-1", DEFAULT_CONTEXT);
|
630 | 631 | assertThat(extractPipelineElement(target, 0, "$project")).containsKey("name");
|
631 | 632 | }
|
| 633 | + |
| 634 | + @Test // GH-3917 |
| 635 | + void inheritedFieldsExposingContextShouldNotFailOnUnknownFieldReferenceForRelaxedRootContext() { |
| 636 | + |
| 637 | + List<AggregationOperation> aggregationOperations = new ArrayList<>(); |
| 638 | + |
| 639 | + GroupOperation groupOperation = Aggregation.group("_id", "label_name"); |
| 640 | + aggregationOperations.add(groupOperation); |
| 641 | + |
| 642 | + ProjectionOperation projectionOperation = Aggregation.project("label_name").andExclude("_id"); |
| 643 | + aggregationOperations.add(projectionOperation); |
| 644 | + |
| 645 | + Sort sort = Sort.by(Sort.Direction.DESC, "serial_number"); |
| 646 | + SortOperation sortOperation = new SortOperation(sort).and(Sort.Direction.DESC, "label_name"); |
| 647 | + aggregationOperations.add(sortOperation); |
| 648 | + |
| 649 | + MongoMappingContext mappingContext = new MongoMappingContext(); |
| 650 | + QueryMapper queryMapper = new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext)); |
| 651 | + |
| 652 | + List<Document> documents = newAggregation(City.class, aggregationOperations).toPipeline(new RelaxedTypeBasedAggregationOperationContext(City.class, mappingContext, queryMapper)); |
| 653 | + assertThat(documents.get(2)).isEqualTo("{ $sort : { 'serial_number' : -1, 'label_name' : -1 } }"); |
| 654 | + } |
632 | 655 |
|
633 | 656 | private Document extractPipelineElement(Document agg, int index, String operation) {
|
634 | 657 |
|
|
0 commit comments