MongoDB OR和AND查询

3
我正在使用mongoDB数据库,其中我有以下格式的集合。
{ name : name1 , area: a , country : c}
{ name : name2 , area: b , country : c}
{ name : name3 , area: a1 , country : c1}
{ name : name4 , area: b1 , country : c1}

我希望您能提供像这样的查询。
select * from coll where (country =c and area =a) or (country = c1 and area = b1)

在mongodb查询中。

我已经阅读了许多文档,但没有找到合适的答案。

因此,如果有人知道,请回复。

谢谢。

1个回答

6

默认情况下,mongodb 查询中的所有元素都使用 and 运算符。您可以使用 { "$or": [ ... ] } 结构指定 or 运算符,如文档所述。

您的查询将是:

{ "$or": [ { "country": "c", "area": "a" }, { "country": "c1", "area": "b1" } ] }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接