In the code below:
DbModels.prototype.updateById = function(_collection, id, field, value, callback) {
this.getCollection(_collection, function(error, sel_collection) {
if( error ) callback(error)
else {
sel_collection.update({_id: ObjectID.createFromHexString(id)}, {$set: {$[field].value:value}}, function(error, updated) {
if( error ) callback(error)
else callback(null, updated);
});
}
});
};
I would like to use the value of the variable field as the name of the variable in $set. I tried using the following code $[field].value (as you can see in the code above), which doesn't work. Any suggestions how to solve this?
Thanks!