'Mongodb "in" query for pattern search using Spring-data-mongodb
I want to get a list of all persons who have some keywords in their hobbies (for example hockey - case insensitive).
The Java class corresponding to my Mongo collection is
class Person {
String name;
List<String> hobbies;
}
Before saving this document in Mongo collection, I am converting each of the hobby to lowercase.
Per https://docs.mongodb.com/manual/reference/operator/query/in/, such queries are supported using Mongo shell and I am able to get the data using the below command
db.person.find({"hobbies":{$in:[/hockey/]}})
However using the Spring Mongodb (3.2.4), I am not getting the data using code snippet below
Criteria.where("hobbies").in("/"+ "Hockey".toLowerCase() +"/");
Would like to know if there is a way to get the data using Spring library?
Solution 1:[1]
Criteria.where("hobbies").regex("Hockey".toLowerCase(),"i") solved the issue
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Raman |
