mongodb结构就像;
[
{id: "1" , name: "alex"},
{id: "2" , name: "felix"},
{id: "3" , name: "kelix"},
{id: "4" , name: "hannah"}
]
我们假设我想在文档中添加“s”每个文档。
[
{id: "1" , name: "alexs"},
{id: "2" , name: "felixs"},
{id: "3" , name: "kelixs"},
{id: "4" , name: "hannahs"}
]
db.list.updateMany({}, { $set: {name: "$name" + "s"})}
但接下来是script contains errors.
是否可以使用mongodb中的现有值更新字段?