Skip to content

Derived findBy…IgnoreCaseIn query doesn't return expected results [DATAMONGO-2540] #3395

Closed
@spring-projects-issues

Description

@spring-projects-issues

MostafaACHRAF opened DATAMONGO-2540 and commented

The derived query : findByAttributeNameIgnoreCaseIn(.....) 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 soemthing 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


No further details from DATAMONGO-2540

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions