The derived query : findBy**AttributeName**IgnoreCaseIn(.....) doesn't work when working with springboot-starter-data-mongodb.

I have a spring boot application. Content of pom.xml:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependency>`
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo</artifactId>
            <scope>test</scope>
        </dependency>

I have the folowing class Flight:

public class Flight {
    String id;
    String origin;
    String destination;
    LocalDateTime scheduledTime;
.....//getters and setters
}

PagingAndSoring repository :

public interface FlightRepository extends PagingAndSortingRepository<Flight, String> {
    List<Flight> findByOriginIgnoreCaseIn(String... origins);
    ....
}

Test case class :

@DataMongoTest
public class DerivedQueriesTests {
@Test
    public void shouldGetFlightsFromLondonOrMadrid() {
        Flight flight1 = createFlight("Madrid", "morocco");
        Flight flight2 = createFlight("morocco", "egypt");
        Flight flight3 = createFlight("London", "germany");

        flightRepository.save(flight1);
        flightRepository.save(flight2);
        flightRepository.save(flight3);

       List<Flight> flights = flightRepository.findByOriginIgnoreCaseIn("madrid");

       Assertions.assertThat(flights).hasSize(1);
       Assertions.assertThat(flights.get(0)).isEqualToComparingFieldByField(flight1);
   }
}

The test fails, returning 0 elements instead of 1. Here is the log \:

main] o.s.data.mongodb.core.MongoTemplate      : find using query: { "origin" : { "$in" : ["madrid"]}} fields: Document{{}}

The option key/value is messing in the query, maybe this is the cause of the problem. I think the log of a working method should be something like \:

main] o.s.data.mongodb.core.MongoTemplate      : find using query: { "origin" : { "$in" : ["madrid"], "$options" : "i"}} fields: Document{{}}

I did the test for findOriginIgnoreCase and it works correctly. The problem occurs when we add In keyword to the method name.

Comment From: bclozel

I don’t think this issue belongs to Spring Boot. Could you open it in https://jira.spring.io/projects/DATAMONGO/issues ?

Thanks

Comment From: MostafaACHRAF

Ok bclozel, thanks