Java对mongodb进行正则查询?
{"_id":ObjectId("55b74aa9c551a027777eec0b"),"colkey":"{timestmp:1438075544181,num:3,i...
{
"_id" : ObjectId("55b74aa9c551a027777eec0b"),
"colkey" : "{timestmp:1438075544181, num:3, ips:[-1079506422,-1079506420]}",
"timeout" : 0,
}
如上mongodb中的一条记录,我想查询colkey里面timestmp大于某个值的所有记录,该如何查询?用正则? 展开
"_id" : ObjectId("55b74aa9c551a027777eec0b"),
"colkey" : "{timestmp:1438075544181, num:3, ips:[-1079506422,-1079506420]}",
"timeout" : 0,
}
如上mongodb中的一条记录,我想查询colkey里面timestmp大于某个值的所有记录,该如何查询?用正则? 展开
2个回答
2016-01-13 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
用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”));
//模糊查询
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”));
推荐于2016-09-27
展开全部
//模糊查询
private BasicDBObject getLikeStr(String findStr) {
Pattern pattern = Pattern.compile("^.*" + findStr + ".*$", Pattern.MULTILINE);
return new BasicDBObject("$regex", pattern);
}
private BasicDBObject getLikeStr(String findStr) {
Pattern pattern = Pattern.compile("^.*" + findStr + ".*$", Pattern.MULTILINE);
return new BasicDBObject("$regex", pattern);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询