Swa*_*ane 3 mongodb mongodb-scala
我正在使用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}
Run Code Online (Sandbox Code Playgroud)
我想要查询
select * from coll where (country =c and area =a) or (country = c1 and area = b1)
Run Code Online (Sandbox Code Playgroud)
在mongodb查询中.
我已经阅读了很多文档,但没有找到合适的答案.
所以如果有人知道请回复.
谢谢
默认情况下,mongodb查询中的所有元素都使用and运算符.您可以or使用该{ "$or": [ ... ] }构造指定运算符,如文档中所述.
您的查询将是:
{ "$or": [ { "country": "c", "area": "a" }, { "country": "c1", "area": "b1" } ] }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
456 次 |
| 最近记录: |