0

我有一个这样的 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")
}

我试图提取千禧年媒体数据:

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 修饰符应用于非数组

我不解,我确实在拉阵!那么发生了什么?

4

1 回答 1

0

当我正确理解您时,您想从 Network.Millennial Media.App 的数组中删除一个条目。在这种情况下,您必须使用点符号引用嵌套在子文档中的字段:

db.MediationSetup.update(
{
    ApplicationId: "YVo9bEQiDLg2"
},
{
    $pull: { "Network.Millennial Media.App": {
                        "AppId": "APID - Banner",
                        "AppValue": "76970",
                        "Priority": 100
              }
   }
});
于 2013-09-12T12:42:14.113 回答