首页 > 解决方案 > Update many values in nested array mongodb

问题描述

I'm stucked how to update many second level nested array values

How to update in mongodb only all "ware amount" in "wares" (sizes.wares.amount) to 0 (zero) where ware (sizes.wares.ware) is "SFO" in here is the mongo data

{
{
    "_id" : ObjectId("5dc1c8f2e3341fc38ef47698"),
    "productCode" : xxxx",

    "sizes" : [ {
            "size" : "35",
            "wares" : [ 
                {"ware" : "SFO", "amount" : "11" }, 
                {"ware" : "LAX","amount" : "22"}
            ]
        }, 
        {
            "size" : "36",
            "wares" : [ 
                {"ware" : "SFO", "amount" : "33"}, 
                { "ware" : "LAX", "amount" : "44"}
            ]
        }, 
    ]
},
{
    "_id" : ObjectId("5f23e19e6fff1017d2d8e8f1"),
    "productCode" : "yyyy",
    "sizes" : [ 
        {"size" : "35",
            "wares" : [ 
                {"ware" : "SFO", "amount" : "255"}, 
                { "ware" : "LAX","amount" : "333"}
            ]
        }, 
        {
            "size" : "36",
            "wares" : [ 
                {"ware" : "SFO", "amount" : "444"}, 
                {"ware" : "LAX","amount" : "777"}
            ]
        }
    ]
}
}



Thanks in advanced

Juha

标签: mongodb

解决方案


推荐阅读