6

Good morning,

I´m trying to combine regular expression with Spring data mongodb repository using Query annotation. What I want is search one substring inside one string attribute of my mongo document. I have been looking in google and here, but I did not find anything elegant, and I was wondering if Spring data has something official about this using the repositories.

Regards.

Marc
  • 3,683
  • 8
  • 34
  • 48
paul
  • 12,873
  • 23
  • 91
  • 153

1 Answers1

13

It seems like an old question, so maybe you've already had a solution but here how I handled the same issue :

@Query(value = "{'title': {$regex : ?0, $options: 'i'}}")
Foo findByTitleRegex(String regexString);

using the /?0/ notation won't work since Spring Data places a String value with quotes

Alper
  • 571
  • 5
  • 15
  • Hi @Alper how to use $caseInsensitive flag in a criteria query. This is the example of a query I've in my firstName = Criteria.where("firstName").regex(fullName, "i") the query doesn't returns case insensitive results, the results are like Upper case results first and lowercase results after, I want to try with caseinsensitive flag set to true, is there any way to include it in a criteria code. – Ananthu K Kumar Jun 30 '22 at 13:03