Mongodb查询:使用$ match管道中的$ in查询运算符查找某些状态的总体

时间:2018-02-03 01:53:42

标签: mongodb mongodb-query

我正在尝试使用Mongodb Query在$ match管道中使用$ in查询运算符查找某些状态的填充。

我尝试运行此代码,但我不断收到错误。我做错了什么?

db.getCollection("statistics").aggregate(

[
     { $match: {"pop": 1}, "state": {$in: ["MN", "IA", "ND", "SD", "WI"]}}
   ]
);

1 个答案:

答案 0 :(得分:0)

$match$and条件

一起使用
db.getCollection("statistics").aggregate(
    [
        {$match: {
            $and: [
                    {"pop" :{ $eq : 1}},
                    {"state": {$in: ["MN", "IA", "ND", "SD", "WI"]}}
                ]
            }
        }
    ]
);