鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)/ 關(guān)于mongodb更新數(shù)組里的所有對(duì)象內(nèi)容問(wèn)題

關(guān)于mongodb更新數(shù)組里的所有對(duì)象內(nèi)容問(wèn)題

文檔如下:

name: 4,
    list: [
        {
            id: “a”,
            date: 1504195200000,
            other: “c”
        },
        {
            id: “b”,
            date: 1504195200000,
            other: “c”
        }
    ]
}

如何把list數(shù)組下的元素里的other全部一次性更新呢?
嘗試了以下方法:不行…

db.getCollection(‘test’).update({‘name’: 4}, {$set: {‘list.$.other’: ‘a(chǎn)’}}, {multi: true})

不知道為什么?求大神的解決方法,謝謝

回答
編輯回答
我以為

從MongoDB 3.6開始支持這樣的方法,參考文檔:$[]運(yùn)算符
3.6 對(duì)數(shù)組操作做了一些強(qiáng)化,關(guān)于數(shù)組的其他操作參考文檔:Array Update Operators

2017年7月1日 07:33