本文介绍了MongoDB where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有JSON格式的mongoDB"users"集合,我想返回所有具有保密性的数据.我该怎么办?

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
        }
    ]
}

在这里,我想返回具有隐私权的数据.例如,facebook,它具有的隐私等于true.如何为此建立查询?

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 ?

谢谢. :')

推荐答案

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

这篇关于MongoDB where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 12:55
查看更多