MongoError: exception: Cannot apply the positional operator without a corresponding query field containing an array

138 views Asked by At

I am trying to update sub array in following document

{
    "_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
}

I am trying to update with following query

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

But it gives me error:

Cannot apply the positional operator without a corresponding query field containing an array

I just want to increase groups.question_quota.opt_1.cmps this key from above document.

0

There are 0 answers