位置运算符未从查询中找到所需的匹配项

时间:2018-06-21 06:23:56

标签: node.js mongodb mongoose

我尝试了一些此处已经可用的答案,但仍然出现错误,

  

{“ message”:“ WriteError({'code':16837,'index':0,'errmsg':'The   位置运算符未从查询中找到所需的匹配项。   未展开的更新:   aOrder。$。aCart','op':{'q':{'FacebookId':'20035721279'},'u':{'$ push':{'aOrder。$。aCart':{'nQuantity': 1,'_ id':'5b2b431632fb16084f1a9265','sItem':'Pizza   Margherita','nPrice':215}}},'multi':false,'upsert':false}})“,”堆栈“   :“ script:1:10”}

var c = {
    sItem: cart.join(','),
    nPrice: sTotal,
}
User.update({ sFacebookId: sender }, {
    $push: {
        "aOrder.$.aCart": c
    }
}, { $set: { "aOrder.$.sReceiptId": sReceiptId } }, (error, result) => {
    console.log(result);
})

这是我的模特,

aOrder: [{
    sReceiptId: String, 
    aCart: [{
        sItem: String,
        nPrice: Number,
        nQuantity: { type: Number, default: 1 },
    }],
    dTimestamp: {
        type: Date,
        default: Date.now
    }
}],

//收藏:用户

{
    "_id" : ObjectId("5b2b457f5f6a6e095458668a"),
    "sFacebookId" : "2003572109654279",
    "__v" : NumberInt("0"),
    "aOrder" : [ ],
    "eStatus" : "n",
    "dCreatedDate" : ISODate("2018-06-21T11:58:15.003+05:30"),
    "sFacebookGender" : "male",
    "sFacebookName" : "John Mark"
}

0 个答案:

没有答案