在mongodb的查询语句中能够这么写{“a”:$gt(1),"a":$lt(5)}mongodb
但这么查询出来的值会作单个条件匹配,最终结果为a大于1的集合+a小于5的集合函数
若是须要实现去交集,a大于1而且又小于5,就必需要用到$and函数了ui
同条件并列查询:url
{ $and:[{"_id":{$gte:ObjectId("59512f800000000000000000")}}, {"_id":{$lte:ObjectId("595280ff0000000000000000")}}], "url":"http://url" }
模糊查询:spa
使用$regex函数正则模糊查询code
{"url":{$regex:"http://www.baidu.com.cn/\\?"}}
简易式模糊查询htm
{"url":/www.baidu.com/}
查询字段存在的记录blog
{"ui":{$exists:true}}
查询为空的字段class
{name:{$in:[null]}}
查询字段不为空查询
{name:{$ne:null}}
多正则匹配查询or查询
$or:[{"url":{$regex:/http:\/\/(www|m).baidu.com.cn\/netshow\/(.*)\/news(.*).htm/}}, {"url":{$regex:/http:\/\/www.baidu.com.cn\/hot\/(.*)/}}]
多正则匹配查询or查询,简单写法
"$or":[{"url":/www.xxx.com.cn/},{"url":/bbs.xxx.com.cn/}]
and查询
$and:[{"ui":{$exists:true}},{"ui":{$ne:0}}]