Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue May 9, 2020 · 2 comments
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

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

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

According to the MongoDB reference documentation the $in operator does not support any options

@spring-projects-issues
Copy link
Author

MostafaACHRAF commented

Thanks for your response.

Yes you are right, but why the "ignoreCase" doesn't not work ?

@spring-projects-issues spring-projects-issues added type: bug A general bug status: ideal-for-contribution An issue that a contributor can help us with labels Dec 30, 2020
@mp911de mp911de changed the title findByXXXXXIgnoreCaseIn derived query doesn't work with spring-data mongodb [DATAMONGO-2540] Derived findBy…IgnoreCaseIn query doesn't work [DATAMONGO-2540] Feb 18, 2021
@mp911de mp911de changed the title Derived findBy…IgnoreCaseIn query doesn't work [DATAMONGO-2540] Derived findBy…IgnoreCaseIn query doesn't return expected results [DATAMONGO-2540] Feb 18, 2021
@mp911de mp911de added this to the 2.2.14 (Moore SR14) milestone Feb 18, 2021
mp911de pushed a commit that referenced this issue Feb 18, 2021
We now consider the IgnoreCase part of a derived query when used along with In. Strings will be quoted to avoid malicious strings from being handed over to the server as a regular expression to evaluate.

See #3395
Original pull request: #3554.
mp911de added a commit that referenced this issue Feb 18, 2021
Reformat code. Add since tags.

See #3395
Original pull request: #3554.
mp911de pushed a commit that referenced this issue Feb 18, 2021
We now consider the IgnoreCase part of a derived query when used along with In. Strings will be quoted to avoid malicious strings from being handed over to the server as a regular expression to evaluate.

See #3395
Original pull request: #3554.
mp911de added a commit that referenced this issue Feb 18, 2021
Reformat code. Add since tags.

See #3395
Original pull request: #3554.
mp911de pushed a commit that referenced this issue Feb 18, 2021
We now consider the IgnoreCase part of a derived query when used along with In. Strings will be quoted to avoid malicious strings from being handed over to the server as a regular expression to evaluate.

See #3395
Original pull request: #3554.
mp911de added a commit that referenced this issue Feb 18, 2021
Reformat code. Add since tags.

See #3395
Original pull request: #3554.
mp911de pushed a commit that referenced this issue Feb 18, 2021
We now consider the IgnoreCase part of a derived query when used along with In. Strings will be quoted to avoid malicious strings from being handed over to the server as a regular expression to evaluate.

See #3395
Original pull request: #3554.
mp911de added a commit that referenced this issue Feb 18, 2021
Reformat code. Add since tags.

See #3395
Original pull request: #3554.
@mp911de mp911de closed this as completed Feb 18, 2021
@mp911de mp911de removed the status: ideal-for-contribution An issue that a contributor can help us with label Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants