开发者

mongodb ORing and ANDing query

开发者 https://www.devze.com 2023-02-11 02:57 出处:网络
I am using mongoDB database. in which I have collection in below format. { name : name1 , area: a , country : c}

I am using mongoDB database. in which I have collection in below format.

{ name : name1 , area: a , country : c}
{ name : name2 , area: b , country : c}
{ name : name3 , area: a1 , country : c1}
{ name : name4 , area: b1 , country : c1}

i want query like

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

in mongodb query.

I have read many document but not found suitable answer.

So if any one knows please repl开发者_Python百科y.

Thanks


By default, all elements in a mongodb query use the and operator. You can specify an or operator using the { "$or": [ ... ] } construct, as described in the documentation.

Your query will be :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号