mongodb中比較($lt $lte $gt $gte)查詢條件說明


$lt    <   (less  than )

$lte    <=  (less than  or equal to )

$gt   >    (greater  than )

$gte   >=    (greater  than or   equal to)

 

$ne  != (not equal to)不等於  {'age': {'$ne': 20}}

$in  在范圍內  {'age': {'$in': [20, 23]}}   注意用list

$nin  (not in)  不在范圍內{'age': {'$nin': [20, 23]}} 注意用list。這個方法可以計算某個值既不等於x也不等於y

$regex (正則匹配) db.collection.find({'name': {'$regex': '^M.*'}})  匹配以M開頭的名字

$exists      屬性是否存在       {'name': {'$exists': True}}     查找name屬性存在

$type     類型判斷        {'age': {'$type': 'int'}}       age的類型為int

$text      文本查詢      {'$text': {'$search': 'Mike'}}     text類型的屬性中包含Mike字符串

$or  查找多種條件   ({'$or':[{'name':'chen'},{'name':'wang'}]})

 

組合使用方法如下:

db.user.find({"age":{"$gte":18,"$lte":25}})

 

對於日期的條件查詢方法:

db.getCollection('news').find({'pub_date':{'$gte':'2017-07-11  11:0:0'}})

 

2) 不等於 $ne

例子:

db.taobao.find( { age: { $ne : 10} } );
————————————————
版權聲明:本文為CSDN博主「西門大盜」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/xiongzaiabc/article/details/81186998


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM