1 回答
TA贡献1804条经验 获得超3个赞
var tc = [
{"name":"Electronics & Hardware", "new_name" : "Electronics and Hardware"},
{"name":"Furniture & Fittings", "new_name" : "Furniture and Fittings"},
{"name":"Gems & Jewellery", "new_name" : "Gems and Jewellery"},
{"name":"Instrumentation", "new_name" : "IASC"},
{"name":"Iron & Steel", "new_name" : "Iron and Steel"},
]
tc.forEach(x => {
db.trainer_copy.updateMany({"jobRoles.sector.name":x["name"]},
{
$set: {
"jobRoles.$[jobRole].sector.name": x["new_name"]
}
},
{ arrayFilters: [{ "jobRole.sector.name": x["name"] }] }
)
})
在上面的答案中,名称 jobRole 是数组中与过滤器匹配的索引的占位符 { "jobRole.sector.name" : x ["name"] }。
x ["name"] 是旧名称并将其更新为新名称即 x["new_name"]。
添加回答
举报