I am attempting to update (or insert) an attribute of an object within an array in MongoDB, but I don't seem to be able to access the array (apps), or the attribute (appId).
Basically, what's happening is the array of "apps" is being created, but the appId is not populating as it should be.
Can anyone take a look and provide some insight?
Template.CurriculumBuilder.events({
'submit #addToCurriculum': function(e) {
event.preventDefault();
const appId = this._id;
console.log('Here is the app id --> ' + appId)
const userId = Meteor.user()._id;
console.log('Here is the user id --> ' + userId);
const doc = Curriculum.findOne({ user: userId });
console.log('Here is the doc id --> ' + doc._id)
Curriculum.update(doc._id, { $set: { apps: [{ $addToSet: { appId: appId } } ] } } );
console.log('Apps have been added to --> ' + doc._id)
return false;
}
});
UPDATE
As answered below, the DB call should be:
Curriculum.update(doc._id,{ $addToSet: { apps: { appId: appId } } } );