我正在尝试更新mongodb文档中数组中的一些匹配元素。
我想将所有comments.$index.author
从chao
更新为tom
,但我无法弄清楚语法。
这是我想在伪json中做的事情。
在:
{
"author" : "lily",
"contents" : "watch movive",
"comments" : [
{
"comment" : "good",
"author" : "chao",
"votes" : 0
},
{
"comment": "so so",
"author": "chao",
"votes": 3
},
………………,
{
"comment": "bad",
"author": "yong",
"votes": -1
},
]
}
后:
{
"author" : "lily",
"contents" : "watch movive",
"comments" : [
{
"comment" : "good",
"author" : "tom",
"votes" : 0
},
{
"comment": "so so",
"author": "tom",
"votes": 3
},
………………,
{
"comment": "bad",
"author": "yong",
"votes": -1
},
]
}