0

Is their any way to search a column in a collection in mongodb with $in which includes an array of elements for search and also caseInsensitive matching of those elements in the column ? N.B: I can use either Java-Mongodb or SpringMongodb Templete

GoutamS
  • 3,535
  • 1
  • 21
  • 25
  • Repeat for https://stackoverflow.com/questions/10700921/case-insensitive-search-with-in/33418202 but this is required for Java – GoutamS Feb 05 '19 at 21:34
  • hi @LhoBen Ben I already mentioned , I need the same for Java Code. – GoutamS Feb 05 '19 at 21:47

1 Answers1

0

You can try this with Spring Data Mongodb if you need one item of "yourArray" to match acase insensitive string:

query = new Query(Criteria.where("yourArray").regex(Pattern.compile("SEARCH", Pattern.CASE_INSENSITIVE)));

If you need "yourArray elements to be in an array of case insensitive SEARCH items, you would use $in in MongoDB. Then, consider building a regex query string appending "|" to each item, or build an AggregaationOperation composed of one MatchOperation for each item.

charlycou
  • 1,778
  • 13
  • 37