Maria Kari Maria Kari - 5 months ago 28
Node.js Question

MongoDB where clause

I have mongoDB "users" collection in JSON format and I want to return all the data having privacy is true. How can I do it ?

{

"name" : "Maria Kari",
"social" : [
{
"facebook" : "www.fb.com/maria.mongodb",
"privacy" : true
},
{
"twitter" : "www.tw.com/mongodb",
"privacy" : false
}
],
"personal" : [
{
"cell_no" : "+1-99082198414",
"privacy" : true
},
{
"email" : "maria@mongodb.com",
"privacy" : false
}
]
}


Here, I want to return the data having privacy is true. For example, facebook, it has privacy is equal to true. How to build query for this ?

Thank You. :')

Answer
db.users.find( { 
    $or:[{ 'social.privacy': true },{'personal.privacy': true}] 
)
Comments