【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