Update a nested collection in meteor is not a problem (and it is described here : Updating a nested property on a collection object with $set)
Basic way to do it :
Collection.update({sel}, {"$set" : {"address.city": "new address"}});
But what if I want to describe my path with variables ?
This one obviously does not work :
var cityName = "NYC";
Collection.update({sel}, {"$set" : {"address." + cityName: "new address"}});
Sadly this one does not work either:
var path = "address.NYC";
Collection.update({sel}, {"$set" : {path: "new address"}});
Neither does that one:
var object = {"address.NYC": "new address"};
Collection.update({sel}, {"$set" : object});
Well, actually, it works, but not the way I want it. It replace entirely the "address" object, removing the other properties.
Any ideas ?
Is there a way to select the field I want to update in the query part ?