I am currently using a dynamic attribute model with the following structure:
{
SKU: "Y32944EW",
type: "shoes",
attr: [
{ "k": "manufacturer",
"v": "ShoesForAll",
},
{ "k": "color",
"v": "blue",
},
{ "k": "style",
"v": "comfort",
},
{ "k": "size",
"v": "7B"
}
]
}
What I need to do is update some attributes based on other attribute conditions, for example, suggests that I want to update the color to red and the style to sport, where the manufacturer is “ShoesForAll”, if I do this:
collection.update({"attr": { "$elemMatch" : { "k":"manufacturer", "v":"ShoesForAll" } },
{$set: {
attr: [
{ "k": "color",
"v": "red",
},
{ "k": "style",
"v": "sport",
},]
}}
});
I lose other attributes, such as "size", and if I do it like this:
collection.update({
"attr": { "$elemMatch" : { "k":"manufacturer", "v":"ShoesForAll" }},
"attr.k": "color",
"attr.k": "style"
}, {$set: {
"data.$.v": "red",
"data.$.v": "sport"
}})
Only one attribute is updated. Does anyone know how I can update some attributes without losing others or without using a single query for each attribute?
thank