邏輯與 $and:要求滿足所有查詢條件 ,否則返回空
語法:db.集合名.find{ $and: [ { <expression1> }, { <expression2> } , ... , {<expressionN> } ] }
//邏輯與 查詢價格在2000-5000之間的手機 db.product1.find({$and:[{"category":"手機"},{"price":{$gt:2000,$lt:5000}}]})
邏輯或 $or:滿足一個條件就行
語法:db.集合名.find{ $or: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
//邏輯或 查詢食品類和飲料類的食品 db.product1.find({$or:[{"category":"食品"},{"category":"飲料"}]})
異或 $nor:邏輯或原理取反
語法:db.集合名.find{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
//異或 邏輯或取反 db.product1.find({$nor:[{"category":"書籍"},{"category":"手機"}]})
邏輯非 $not :取反查詢條件
語法:db.集合名.find{ field: { $not: { <operator-expression> } } }
//邏輯非 db.product1.find({category:{$not:{$eq:"手機"}}})