【发布时间】:2022-01-01 04:21:57
【问题描述】:
有谁知道如何在 mongo 中更改属性值 来自
我将 JSON.units[0].services[0].label 从 etiket controle 更改为 AuditLabel
我试过这个:
db.getCollection('assortiment').updateMany({"units.$[].services.$[].label": "etiket controle"},{ "$set": { "units.$[].services.$[].label": "AuditLabel" }})
但没有成功,因为它没有选择任何东西
{
"_id" : "764",
"meta" : {
"groupsId" : "764",
"type" : "DRYGR"
},
"units" : [
{
"unit" : "BASE_UNIT_OR_EACH",
"gtin" : "08711728556206",
"services" : [
{
"label" : "etiket controle",
"collection" : "gtins"
}
]
}
]
}
到
{
"_id" : "764",
"meta" : {
"groupsId" : "764",
"type" : "DRYGR"
},
"units" : [
{
"unit" : "BASE_UNIT_OR_EACH",
"gtin" : "08711728556206",
"services" : [
{
"label" : "AuditLabel",
"collection" : "gtins"
}
]
}
]
}
【问题讨论】:
-
如果您不需要搜索,并且您已经知道
JSON.units[0].services[0].label之类的索引,您可以执行this 之类的操作,如果您想在任何情况下更新它,您可以删除搜索,但是我想你不想要这个,你想在任何地方更新标签,但不确定