mongo一个字段有两个条件进行查询

Posted calinayc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ] )

 

以上是关于mongo一个字段有两个条件进行查询的主要内容,如果未能解决你的问题,请参考以下文章