文档:
{
......
"keywords" : [
"Collections",
" ArrayList",
" LinkedList"
]
.....
}
输入数组["collections", "map",...]
Input 数组元素。如何使用MongoTemplate Spring Boot Application来实现这一点
当前方法:
Query query = new Query();
List<BsonRegularExpression> list =new ArrayList<>();
for (String s : searchWords) {
list.add(new BsonRegularExpression("^" + s, "i"));
}
Criteria criteria = Criteria.where("keywords").in(list);
query.addCriteria(criteria);
System.out.println(query.toString());
List<Question> questions = mongoTemplate.find(query, Question.class);
这是正确的方法还是我缺少一些东西