4

Can any one suggest me , How to use "findbynameRegexIgnorecase" in mongorepository? I need to check (regex,Ignorecase) while finding the name itself. spring1.4.2.Release

public interface SampleAreaMongoRepository extends MongoRepository<SampleArea, String> {
SampleArea findByAreaRegexIgnoreCase(String area);}
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
vignesh
  • 83
  • 7

1 Answers1

4

Well, you can achieve this with SpringData mongo finder @Query annotation.

The query annotation was from org.springframework.data.mongodb.repository package

public interface MyMongoRepository extends MongoRepository<Users, String>{

    @Query(value = "{'name': {$regex : ?0, $options: 'i'}}")
    List<Users> findByAreaRegexIgnoreCase(String name);

}

$regex : ?0 is the regex accepting input name as the parameter and $options: 'i' to ignore the case.

Hope this helps and good luck!

harshavmb
  • 3,404
  • 3
  • 21
  • 55