I'm trying to remove an Schema object from an array in a document using SimpleSchema and Mongo.
TrainingSchema = new SimpleSchema({
....
// irrelevant fields
....
exercises: {
type: Array,
optional: true,
autoform: {
type: "hidden"
}
},
'exercises.$': {
type: ExerciseSchema
}
});
An inserted ExerciseSchema Object into the trainingSchema looks like this. sample Array
to insert the Object I'm using this. It works:
addToTraining(trainingId, exercise) {
Trainings.update(trainingId, {$addToSet: {exercises: exercise}});
}
But to remove the whole object from the array I tried this and some others.
removeExerciseFromTraining(trainingId, exercise) {
Trainings.update(trainingId, {$pull: {exercises: {_id: exercise._id}}});
}
How can I do this?