close
文章出處

1、條件>,<,>=,<=在MongoDB中的寫法

  >:$gt,<:$lt,>=:$gte,<=:$lte,<>:$ne

  具體使用方法:

db.class.find({"filed":{$gt:value}})  filed>value

db.class.find({"filed":{$lt:value}})   filed<value

db.class.find({"filed":{$gte:value}})   filed>=value

db.class.find({"filed":{$lte:value}})  filed<=value

db.class.find({"filed":{$gt:value,$lt:value1}})  value1>filed>value

db.class.find({"filed":{$ne:5}})    filed<>value

db.class.find({"stuCount":{$gt:10}})
db.class.find({"stuCount":{$gte:10}})
db.class.find({"stuCount":{$lt:10}})
db.class.find({"stuCount":{$lte:10}})
db.class.find({"stuCount":{$lt:10,$gt:5}})
db.class.find({"stuCount":{$ne:5}})

2、$all匹配所有

    這個操作符跟 SQL 語法的 in 類似,但不同的是, in 只需滿足( )內的某一個值即可, 而$all 必
  須滿足[ ]內的所有值

  db.class.find({stuCount:{$all:[6,8]}}) 查詢結果為空

  db.class.find({stuCount:{$all:[6]}}) 可以查出一條,等同于db.class.find({"stuCount":6})

3、$in包含

  與 sql 標準語法的用途是一樣的,即要查詢的是一系列枚舉值的范圍內

  db.class.find({stuCount:{$in:[6,8]}})

4、$nin不包含

  db.class.find({stuCount:{$nin:[6,8]}})

5、判斷字段是否存在

  db.class.find({stuCount:{$exists:true}})

6、NULL值處理

  db.class.find({name:null}) 會查詢出沒有name字段的數據

  db.class.find({name:{"$in":[null],"$exists":true}}) 查詢結果為有name字段,且name=null

7、$mod取余

  db.class.find({stuCount:{$mod:[7,2]}})  對7取余等于2

 


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 AutoPoster 的頭像
    AutoPoster

    互聯網 - 大數據

    AutoPoster 發表在 痞客邦 留言(0) 人氣()