mongoDb复杂条件查询(or与and)

关系数据库:select * from where(state1=11 and state2=22) or value >300

首先使用MongoDB的方式查询:

分为以下几个步骤实现:

步骤一:实现 (state1=11 and state2=22)

db.col.find(

    {$and:[{"state1":11},{"state2":22}]}

    )

步骤二:使用or形式实现 value >300

db.col.find(

    { $or:[{"value":{$gte:300}}] }

    )

步骤三:将步骤一参数拼接到步骤二or条件

db.col.find({$or:

          [

            {$and:[{"state1":11},{"state2":22}]},{"value":{$gte:300}}

          ]

        })

猜你喜欢

转载自blog.csdn.net/weixin_33845477/article/details/87625212