【mongo】一個字段有兩個條件進行查詢


條件:查詢status:2,has_pay:true,amount:不等於0,type:A或者空(type類型有4個,分別是A、B、C、以及部分字段為空)的訂單
 

反向查詢:

db.order.find({ "status": NumberInt(2), "has_pay": true, "amount": { $ne: NumberInt(0) },$and: [ { "type":{ $ne: "C" } }, { "type": { $ne: "B"} } ]})

或者

db.order.find({ "status": NumberInt(2), "has_pay": true, "amount": { $ne: NumberInt(0) }, $nor: [ { "type": "C" }, { "type": "B" } ] }) 

 

正向查詢:

db.order.find({ "status": NumberInt(2), "has_pay": true, "amount": { $ne: NumberInt(0) }, $or: [ { "type": "A" }, { "type": null } ] })

 


免責聲明!

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



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