【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 } ] })

 
原文地址:https://www.cnblogs.com/Calinayc/p/11551762.html