Meteor Collection Hooks Updating Element On A Position In Array
i have this object: card: { customFields [ { id, value }, {id , value } ... ] } A customFields array is inside cards, which contans elements consisting of an id and a value. Now i
Solution 1:
Found a solution:
modifier.$set[`customFields.${ index }.value`]
Solution 2:
It looks like you'll need to do it using a second update:
update(selector, modifier, options, callback) {
let i = 1;
let val = 20;
// The field in the array you want to modifylet _modifier = {$set: {"customFields.$.value": val}};
// The selector for main element and the array elementlet _selector = Object.assign(selector, {"customFields.id": i});
// Update the arraysuper.update(_selector, _modifier);
// Continue with the actual updatereturnsuper.update(selector, modifier, options, callback);
}
I'm assuming it's safe to call super.update()
twice in the same hook.
Post a Comment for "Meteor Collection Hooks Updating Element On A Position In Array"