Reputation: 6491
Saying i have a multivalue field in a mongo document:
public class MongoEntity{
private List<String> field;
}
What would be the correct criteria for querying a regex in that field?
I've tried
Criteria.where(searchText).regex(searchText).in("field");
But that results in
org.springframework.data.mongodb.UncategorizedMongoDbException:
Can't canonicalize query: BadValue unknown top level operator: $in;
nested exception is com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $in
Upvotes: 3
Views: 7923
Reputation: 227
This is working
List<Pattern> regs = new ArrayList<Pattern>()
regs.add(Pattern.compile(regex, Pattern.CASE_INSENSITIVE))
Criteria.where("tags").regex(regs)
Upvotes: 0
Reputation: 6491
So after many trial and errors, turns out it's simpler (although a little counter-intuitive in my opinion) than it thought:
Criteria.where("field").regex(searchText);
Upvotes: 3