关于mongodb更新数组里的所有对象内容问题。。。。
发布于 8 年前 作者 oxgos 6320 次预览 最后一次回复是 8 年前 来自 问答
###文档如下:
{
name: 4,
list: [{
id: "a",
date: 1504195200000,
other: "c"
},{
id: "b",
date: 1504195200000,
other: "c"
}]
}
如何把list数组下的元素里的other全部一次性更新呢? 尝试了以下方法:不行…
db.getCollection('test').update({'name': 4}, {$set: {'list.$.other': 'a'}}, {multi: true})
不知道为什么?求大神的解决方法,谢谢
7 回复
MongoDB 3.6 版本的话可以这样 db.test.update({name: 4}, {$set: {‘list.$[].other’: ‘a’}}, {multi: true})
好
好的
不错
顶
@beyond5959 谢谢大神,终于好了,原来3.6新特性有…一直没注意
@beyond5959 求助为什么我还是不行,版本是3.6.0