mongodb中比較級查詢條件:($lt $lte $gt $gte)(大於、小於)、查找條件


 

查詢表中學生年級大於20,如下:

db.getCollection('student').find({'age':{'$gt':'20'}})

 

$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

$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'}})


免責聲明!

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



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