Home > Software design >  Spring Mongo query not ignoring case
Spring Mongo query not ignoring case

Time:12-04

I've the following query that is not ignoring case. What could be done to make this be case insensitive?

@Query("{'occasionId':?0,'text':/.*?1.*/}")
Page<FreeMessageCard> findByOccasionIdAndTextIgnoreCase(String occasionId, String text, Pageable pageable);

CodePudding user response:

If you use @Query annotation, spring-data will not generate another query based on the naming convention for method names. If you want it to generate a query for you - don't use @Query annotation. Besides that, you can make your query work by doing this:

@Query("{'occasionId':?0,'text':/.*?1.*/i}")
Page<FreeMessageCard> findByOccasionIdAndTextIgnoreCase(String occasionId, String text, Pageable pageable);
  • Related