问题
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
回答1:
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);
来源:https://stackoverflow.com/questions/35623672/spring-mongotemplate-find-by-regex-in-collection