MongoError:exception:如果没有包含数组的相应查询字段,则无法应用位置运算符

时间:2016-02-02 13:22:47

标签: arrays mongodb mongoose positional-operator

我正在尝试更新以下文档中的子数组

{
    "_id" : ObjectId("56b079d937fc13691b25c354"),
    "clks" : 4,
    "compl" : 0,
    "crtd_on" : ISODate("2016-02-02T09:41:45.047Z"),
    "default" : [],
    "end_dt" : ISODate("2016-02-23T18:30:00.000Z"),
    "fails" : 0,
    "groups" : [ 
        {
            "N" : 100,
            "alert_msg" : 0,
            "clks" : 4,
            "cmps" : 0,
            "color" : 0,
            "fls" : 0,
            "grp_id" : 5453,
            "grp_nm" : "Last Quota",
            "oq" : 0,
            "question_quota" : [ 
                {
                    "q_id" : 96,
                    "q_key" : "AGE",
                    "q_cat" : 1,
                    "fls" : 0,
                    "cmps" : 0,
                    "opt_1" : {
                        "opt_id" : 1,
                        "startAge" : 18,
                        "endAge" : 35,
                        "N" : 100,
                        "fls" : 0,
                        "cmps" : 0
                    },
                    "opt_2" : {
                        "opt_id" : 2,
                        "startAge" : 40,
                        "endAge" : 60,
                        "N" : 100,
                        "fls" : 0,
                        "cmps" : 0
                    }
                }
            ],
        }
    ],
    "grs_prf" : 0,
    "grs_prf_per" : 0,
    "id" : 5165,
    "last_clk_dt" : ISODate("2016-02-02T11:38:00.078Z"),
    "mod_on" : ISODate("2016-02-02T12:28:15.556Z"),
    "n" : 100,
    "nm" : "2Feb",
    "oq" : 0,
    "rev" : 0,
    "rew" : 0,
    "sortNm" : "2feb",
    "st" : 1,
    "str_dt" : ISODate("2016-02-01T18:30:00.000Z"),
    "supp" : 0
}

我正在尝试使用以下查询进行更新

db.getCollection('job_stats').update({ id: 5165, 'groups.grp_id': 5453, 'groups.question_quota.q_id': 96, 'groups.question_quota.opt_1.opt_id': 1 },{ '$set': { mod_on: new Date("Tue, 02 Feb 2016 13:12:26 GMT") }, '$inc': { 'groups.$.question_quota.$.opt_1.cmps': 1 } },{upsert: false})

但它给了我错误:

  

如果没有包含数组的相应查询字段

,则无法应用位置运算符

我只想从上面的文档中增加groups.question_quota.opt_1.cmps这个键。

0 个答案:

没有答案