I am currently using a dynamic attributes model with the next 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 of the attributes based on other attributes conditions, for example, lets suppose that I want to update the color to red and style to sport where manufacturer is "ShoesForAll", If I do it like this:
collection.update({"attr": { "$elemMatch" : { "k":"manufacturer", "v":"ShoesForAll" } },
{$set: {
attr: [
{ "k": "color",
"v": "red",
},
{ "k": "style",
"v": "sport",
},]
}}
});
I am losing other attributes like "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. Anyone knows how can I update some of the attributes without losing the others ones or without using one query for each attribute?
Thanks