2011-02-15 175 views
3

我使用的MongoDB數據庫。其中我收集在以下格式。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} 

我想在MongoDB中查詢查詢像

select * from coll where (country =c and area =a) or (country = c1 and area = b1) 

我看了很多文件,但沒有找到合適的解決辦法。

因此,如果任何人知道請回復。

感謝

回答

6

默認情況下,在MongoDB的查詢中的所有元素使用and操作。您可以使用{ "$or": [ ... ] }構造指定or運算符,如documentation中所述。

您的查詢將是:

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

由於它的工作 – 2011-02-16 07:01:52