标签: mongodb
我试图找出如何进行嵌套OR / AND,其中查询就像你在MySQL中做的那样
以示例为例
SELECT first_name, id FROM table WHERE ( province = "nb" OR province = "on" ) AND ( city = "toronto" AND first_name = "steven" )
答案 0 :(得分:24)
MongoDB中的查询如下所示:
Database.collection_name.find( // This is the condition { $and: [ { $or: [ {province: 'nb'}, {province: 'on'} ] }, { city: "toronto" }, { first_name: "steven" } ] }, // Specify the fields that you need { first_name: 1, _id: 1 } )
$and $or
MongoDB的一些示例和官方文档找到here。