diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java index 33720d2557..20e333e348 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java @@ -1275,6 +1275,11 @@ void readsClosedProjection() { assertThat(repository.findClosedProjectionBy()).isNotEmpty(); } + @Test // https://github.com/spring-projects/spring-data-mongodb/issues/4839 + void findAggregatedClosedProjectionBy() { + assertThat(repository.findAggregatedClosedProjectionBy()).isNotEmpty(); + } + @Test // DATAMONGO-1865 void findFirstEntityReturnsFirstResultEvenForNonUniqueMatches() { assertThat(repository.findFirstBy()).isNotNull(); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java index c2036cabf9..09ead80617 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java @@ -386,6 +386,10 @@ Page findByCustomQueryLastnameAndAddressStreetInList(String lastname, Li // DATAMONGO-1752 Iterable findClosedProjectionBy(); + // https://github.com/spring-projects/spring-data-mongodb/issues/4839 + @Aggregation("{ '$project': { _id : 0, firstName : 1, lastname : 1 } }") + Iterable findAggregatedClosedProjectionBy(); + @Query(sort = "{ age : -1 }") List findByAgeGreaterThan(int age);