I have the following records in a collection:
{
id : id_value,
streams : [
{ a : a_value, b : b_value, c : c_value },
{ a : a_value, b : b_value, c : c_value }, ...
]
}
I want to be able to change the c_value of a particular entry in the streams array. I've been using a two step process of doing this, pulling out an entry from the streams array, creating a new entry and adding it back to the streams array. This works, but doesn't seem the most efficient way of accomplishing this. Is there a better approach that I can use? Below is the code that I'm currently using:
db.users.update({id:user},
{$pull : {streams : {$and : [{a : a_value}, {b : b_value}]}}},
{w:1}, cb);
new_entry = { a : old_a_value, b : old_b_value, c : new_c_value}
db.users.update({id:user},
{$addToSet : {streams : new_entry}}, {w:1}, cb);
Thank You, Gary