I'm trying to do something tricky but I'm not sure if that's the way to go. Here it is :
I have an user with object dispos. Dispos contains arrays of months, so can be
user.dispos: {"02-2015" : [], "05-2015" : [] }
Now, I want to do a dynamic update of the specific month, for example I want to only update the user.dispos["02-2015"] field and not replace the whole dispos object, letting the ["05-2015"] remaining. For now I tried :
User.update({ _id: req.body.id },
{ $set: { dispos["02-2015"]: disposOf-02-2015} }, function(error){
if (error) return res.send(500, err);
return res.send(204) });
It doesn't work, but you get what I mean... I want to update dispos at a certain position, not replacing the whole property. Thanks for your help.
edit
It's nearly there by using the dot notation and wrapping the property name in quotes. I'm using a variable to set the month-year of dispos. With $set: { "dispos.monthYear": dispos } I get dispos : { "monthYear" : { "06-2015 : [] ...} }. Well, I just dont need this "monthYear" level which should be the dynamic mont-year name. In this case monthYear = "06-2015" so I would like to get dispos : { "06-2015": []...} which doesn't erase my other dispos {"07-2015"}
disposOf-02-2015? Or was that supposed to be text"disposOf-02-2015"?