在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}}]