用Java实现MongoDB正则查询小技巧
用Java实现MongoDB正则查询小技巧: //模糊查询 private BasicDBObject getLikeStr(String findStr) { Pattern pattern = Pa
用Java实现MongoDB正则查询小技巧:
//模糊查询
private BasicDBObject getLikeStr(String findStr) {
Pattern pattern = Pattern.compile("^.*" + findStr + ".*$", Pattern.CASE_INSENSITIVE);
return new BasicDBObject("$regex", pattern);
}
DBObject query = new BasicDBObject();
query.put("real_name", getLikeStr(userName));
//endWith文件扩展名
private BasicDBObject endWithStr(String findStr) {
Pattern pattern = Pattern.compile(findStr + "$", Pattern.MULTILINE);
return new BasicDBObject("$regex", pattern);
}
DBObject query = new BasicDBObject();
query.put("filename", endWithStr(“.pdf”));
上一篇: unicode的编码解码
下一篇: Linux中不可改变位权限