I want to rename a field inside a object itself inside a nested array.
As example, I want to rename the all tags m2
to m6
in this document:
{
"_id": 1,
"tagsGroup": [
{
"id": "1234",
"tags": {
"m1": 1,
"m2": 2
}
},
{
"id": "456",
"tags": {
"m3": 1,
"m2": 2
}
},
{
"id": "1234",
"tags": {
"m4": 2,
"m5": 2
}
},
]
}
This is my current state of work:
db.collection.update({},
{
"$set": {"tagsGroup.$[tGp].tags.m6": "$tagsGroup.$[tGp].tags.m2"},
"$unset": {"tagsGroup.$[tGp].tags.m2": ""}
},
{
arrayFilters: [{"tGp.tags.m2": {$exists: 1}}],
multi: true}
)
Unfortunately, the $tagsGroup.$[tGp].tags.m6
is not interpreted.
Do you guys, have a way to do this?
Thanks!
question from:
https://stackoverflow.com/questions/65950455/mongodb-get-value-from-identifier-in-update 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…