Mongo Collection(使用Meteor)比较密钥内部文件的字符串值

时间:2016-04-26 15:03:41

标签: mongodb meteor

我试图让find返回所有匹配的文档,其中orderStatus是'Pending'或'In Progress',执行此查询的最简单方法是什么?非常感谢!

MyCollection.find({ user: currentUserId,
    { $or:
      [{orderStatus : "Pending"},
       {orderStatus : "In Progress"}] }});

1 个答案:

答案 0 :(得分:0)

使用 $in 运算符,如下所示:

MyCollection.find({ 
    "user": currentUserId,
    "orderStatus": { "$in": ["Pending", "In Progress"] }
});

以上查询是使用 $or 运算符的以下查询的更简单版本:

MyCollection.find({ 
    "user": currentUserId,
    "$or": [
        { "orderStatus": "Pending" },
        { "orderStatus": "In Progress" }
    ]
});