需要帮助mongodb $ pull

时间:2013-09-12 08:45:47

标签: mongodb mongodb-query

我有一个类似的mongodb文档:

{
    "_id": ObjectId("5231718f042f8bc215000007"),
    "ApplicationId": "YVo9bEQiDLg2",
    "Network": {
        "Millennial Media": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 352,
            "App": [
                {
                    "AppId": "APID - Banner",
                    "AppValue": "76970",
                    "Priority": 100
                }
            ]
        },
        "Buzzcity": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 353,
            "App": [
                {
                    "AppId": "Partner ID",
                    "AppValue": "80624",
                    "Priority": 100
                }
            ]
        },
        "Adiquity": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 354,
            "App": [
                {
                    "AppId": "package",
                    "AppValue": "com.ristomobile.giftntake",
                    "Priority": 0
                },
                {
                    "AppId": "Site ID",
                    "AppValue": "adqkkqkk-14eo91zj-qv6qt",
                    "Priority": 100
                },
                {
                    "AppId": "appName",
                    "AppValue": "Gift&Take",
                    "Priority": 0
                }
            ]
        },
        "Smaato": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 351,
            "App": [
                {
                    "AppId": "Adspace ID",
                    "AppValue": "65766605",
                    "Priority": 100
                }
            ],
            "Partner": [
                {
                    "PartnerId": "Publisher ID",
                    "PartnerValue": "923862008"
                }
            ]
        },
        "AdNear": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 367,
            "Partner": [
                {
                    "PartnerId": "pubid",
                    "PartnerValue": "rs-1328"
                },
                {
                    "PartnerId": "api_key",
                    "PartnerValue": "RSW78:QH8HHM389M7YP"
                }
            ]
        },
        "twinpine": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 371,
            "Partner": [
                {
                    "PartnerId": "pid",
                    "PartnerValue": "1551a74d1df075a"
                },
                {
                    "PartnerId": "alid",
                    "PartnerValue": "405"
                }
            ]
        },
        "Vserv.mobi": {
            "Active": true,
            "RefreshInterval": 300000,
            "NetworkId": 370,
            "Partner": [
                {
                    "PartnerId": "Zone Id",
                    "PartnerValue": "32024"
                },
                {
                    "PartnerId": "Publisher Id",
                    "PartnerValue": "12649"
                }
            ]
        }
    },
    "LastUpdate": ISODate("2013-06-24T01:44:22.865Z")
}

我试图取消Millenial Media数据:

db.MediationSetup.update(
{
    ApplicationId: "YVo9bEQiDLg2"
},
{
    $pull: {
        Network: {
            "Millennial Media": {
                "Active": true,
                "RefreshInterval": 300000,
                "NetworkId": 352,
                "App": [
                    {
                        "AppId": "APID - Banner",
                        "AppValue": "76970",
                        "Priority": 100
                    }
                ]
            }
        }
    }
})

但它给出了

  

无法将$ pull / $ pullAll修饰符应用于非数组

我很困惑,我确实在拉阵!发生了什么事?

1 个答案:

答案 0 :(得分:0)

当我理解正确时,您想从Network.Millennial Media.App中删除数组中的条目。在这种情况下,您必须使用dot-notation

引用嵌套在子文档中的字段
db.MediationSetup.update(
{
    ApplicationId: "YVo9bEQiDLg2"
},
{
    $pull: { "Network.Millennial Media.App": {
                        "AppId": "APID - Banner",
                        "AppValue": "76970",
                        "Priority": 100
              }
   }
});