猫鼬更新嵌套级别数组对象

时间:2018-08-28 10:05:35

标签: mongoose mongodb-query

我在更新两个字段brandSerialNumberbrand时遇到问题,我还想在mongo db中标记数组字段的下方添加一个名称为delivaryquantity的新键。是我的文件

{
    "_id": {
        "$oid": "5b811a01372fc4000414a62c"
    },
    "cartobject": [
        {
            "_5b6550bfc6def200042acc7d_Avira_30": {
                "_id": "5b6550bfc6def200042acc7d",
                "sku": "9",
                "brandSerialNumber": "2",
                "quantity": 1,
                "productName": "dummi 2",
                "brand": "Avira",
                "pack": {
                    "packvalue": "30",
                    "totpack": "30",
                    "innerpack": "1",
                    "packcharges": "0"
                },
                "price": 3000,
                "brandPrice": "3100",
                "offerMaxKgLimit": 60,
                "qtyInKg": 30,
                "offer": "10",
                "offerPrice": 3100,
                "staticOfferPrice": 3100,
                "offerId": "5b811902372fc4000414a62a",
                "fullOffer": {
                    "_id": "5b811902372fc4000414a62a",
                    "offerstartdate": "2018-08-16T00:00:00.000Z",
                    "offerenddate": "2018-08-26T00:00:00.000Z",
                    "productname": "dummi 2",
                    "offerproductid": "5b6550bfc6def200042acc7d",
                    "productbrand": "Avira",
                    "pack": "30",
                    "offerinfo": "testing ",
                    "priceoffer": "10",
                    "maxlimituser": "60",
                    "maxlimituserunit": "Kg",
                    "startdatemiliseconds": 1534377600000,
                    "enddatemiliseconds": 1535241600000,
                    "offersizeunit": "qtl",
                    "offersize": 2,
                    "offerremaingquantity": 0,
                    "priceofferunit": "rupees",
                    "priceofferapplied": "perpack",
                    "filepath": "public/uploads/offer/1535187138151-pexels-photo-433527.jpeg",
                    "filename": "1535187138151-pexels-photo-433527.jpeg",
                    "__v": 0
                },
                "discountOnQuantity": 10,
                "staticDiscountOnQuantity": 10,
                "transportCharge": 8,
                "transportRate": 8,
                "totalItemPrice": 936
            }
        }
    ],
    "orderdate": {
        "$date": "2018-08-25T14:27:36.000Z"
    },
    "customername": "1111",
    "brokername": "for testing",
    "amount": 928,
    "orderid": 1535187396908,
    "ordernote": "",
    "userid": "5b50375de1b8d4000485ffd6",
    "transportcharge": 8,
    "ordermilisecond": 1535187456640,
    "customernumber": null,
    "brokernumber": null,
    "__v": 0
}

我已经尝试了mongo db官方文档以及此平台上的所有内容,但是找不到正确的答案。这是我尝试过但找不到正确答案的查询

 Order.update(query, {'$set': {
        'cartobject._5b6550bfc6def200042acc7d_Avira_30.$.brand': 'Udan',
        'cartobject._5b6550bfc6def200042acc7d_Avira_30.$.brandSerialNumber': 1
    }}, function(err) {
        if(err){
            res.json({ 'success': false, 'message': err });
        } else {
            res.json({ 'success': true, 'message': 'success' });
        }
    });

请帮助我解决这个问题,因为我是Node js和mongo db的新手。

0 个答案:

没有答案