使用客户端工具进行模糊查询
- 列表内容
{“content”:”$regex”: “123456”}
其他情况模糊查询
查询包含XXX
2.
{name:/xxx/}
查询以XXX开头
3.{name:/^xxx/}
查询以XXX结尾
4.
{name:/xxx^/}
查询忽略大小写
5.
{name:/xxx/i}
Spring中不区分大小写的模糊查询
/完全匹配
Pattern pattern = Pattern.compile("^王$", Pattern.CASE_INSENSITIVE);
//右匹配
Pattern pattern = Pattern.compile("^.*王$", Pattern.CASE_INSENSITIVE);
//左匹配
Pattern pattern = Pattern.compile("^王.*$", Pattern.CASE_INSENSITIVE);
//模糊匹配
Pattern pattern = Pattern.compile("^.*王.*$", Pattern.CASE_INSENSITIVE);
Query query = Query.query(Criteria.where(fieldName).regex(pattern));
List<simpleuserinfo> users = mongoTemplate.find(query, SimpleUserInfo.class, classname);
return users;
转自 https://www.2cto.com/database/201710/688372.html