如果满足条件,则更新数组中的每个元素

时间:2019-04-02 11:24:28

标签: mongodb

如果日期存在,我想更新数组中的每个元素(添加值为0的分数列)。请提供3.4版本的答案,而不使用$ []运算符,因为3.4版本不支持此运算符

数据就是这样

{
    "u_id" : "79049",
    "array" : [
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "2",
            "date" : "2019-03-29 06:03:13"
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3",
            "date" : "2019-03-29 06:03:13"
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3"
        }
    ],
    "Status" : 1
}

我想要的数据

{
    "u_id" : "79049",
    "array" : [
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "2",
            "date" : "2019-03-29 06:03:13",
            "score":0
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3",
            "date" : "2019-03-29 06:03:13",
            "score":0
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3"
        }
    ],
    "Status" : 1
}

0 个答案:

没有答案