Mongodb高級查詢

1.查詢操作符
1)條件操作符
--查找年齡大於13的學生
db.student.find({age:{$gt:13}});
--查找年齡小於15的學生
db.student.find({age:{$lt:15}});
--查找年齡大於等於13的學生
db.student.find({age:{$gte:13}});
--查找年齡小於等於15的學生
db.student.find({age:{$lte:15}});
--查找年齡小於15且大於13的學生
db.student.find({age:{$gt:13,$lt:15}});
2)$all匹配所有
--查找hobby包含"orage"和"apple"的學生
db.student.find({hobby:{$all:["orange","apple"]}});
3)$exists判斷字段是否存在
--查詢所有包含hobby字段的學生
db.student.find({hobby:{$exists,true}});
--查詢所有不包含hobby字段的學生
db.student.find({hobby:{$exists,false}});
4)null值處理
--查找包含hobby字段且其值爲null的學生
db.student.find({hobby:{"$in":[null],"exists":true}});
5)$mod取模運算
--查找學生年齡取模10後等於1的學生
db.student.find({age:{$mod,[10,1]}});
6)$ne不等於
--查找學生年齡不等於13的學生
db.student.find({age:{$ne:13}});
7)$in包含於
--查找年齡等於11,13,15的學生
db.student.find({age:{$in:[11,13,15]}});
8)$nin不包含於

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章