je kunt $[]
. gebruiken positional-all
om geneste array-elementen te updaten, mongo doc voor $[]
vraag
db.t14.update(
{},
{ $set: { "calc.$[].datasets.$[elem].name": "updated" } },
{ arrayFilters: [ { "elem": "x1" } ], multi: true}
)
voorbeeldverzameling met een document
> db.t14.findOne()
{
"_id" : 1,
"calc" : [
{
"preset" : "abc",
"datasets" : [
{
"_id" : "x1",
"name" : "n1"
},
{
"_id" : "x2",
"name" : "n2"
}
]
}
]
}
bijwerken
> db.t14.update({},{$set: { "calc.$[].datasets.$[elem].name": "newname" } },{ arrayFilters: [{ "elem.name": "n1" }], multi: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
post-update
> db.t14.findOne()
{
"_id" : 1,
"calc" : [
{
"preset" : "abc",
"datasets" : [
{
"_id" : "x1",
"name" : "newname"
},
{
"_id" : "x2",
"name" : "n2"
}
]
}
]
}
>