Good evening. I’m working on the Exercise Tracker and trying to figure out how to insert a new exercise log into an existing record.
This is what I have so far:
var findAndUpdate = function(userInput, done) {
User.findOneAndUpdate(
{
_id: userInput.user_id
}, {
log: [{
description: userInput.desc,
duration: userInput.dur,
date: userInput.date
}]
}, (err, data) => {
if (err) {
done(err);
}
done(null, data);
}
)
};
The problem with that code is it updates the exercise log, instead of adding a new one. So I tried this instead:
User.insert(
{
_id: userInput.user_id,
log: [{
description: userInput.desc,
duration: userInput.dur,
date: userInput.date
}]
}, (err, data) => {
if (err) {
done(err);
}
done(null, data);
})
The problem with that code is I’m getting an error:
TypeError: User.insert is not a function
I have the User schema set up properly, so there must be something wrong with the way I wrote the insert code?
Live Version: https://dog-comic.glitch.me/