MongoDB where clause

你。 提交于 2019-12-12 05:38:03

问题


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. :')


回答1:


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


来源:https://stackoverflow.com/questions/37769629/mongodb-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!