Mongo Multi Update
gebruiken trek eerst alle k:[color,style]
en dan addToSet
in attr
array gegeven waarden. Update-query ziet er als volgt uit:
db.runCommand({
"update": "sku",//here sku is collection name
"updates": [{
"q": {
"attr.k": "manufacturer",
"attr.v": "ShoesForAll"
},
"u": {
"$pull": {
"attr": {
"k": {
"$in": ["color", "style"]
}
}
}
},
"multi": true
}, {
"q": {
"attr.k": "manufacturer",
"attr.v": "ShoesForAll"
},
"u": {
"$addToSet": {
"attr": {
"$each": [{
"k": "color",
"v": "red"
}, {
"k": "style",
"v": "sport"
}]
}
}
}
}]
})