The method is returning undefined. I.g., finishing before the findOneAndUpdate
resolves.
exports.updateMovie = async (movie) => {
try {
return await Movie.findOneAndUpdate({_id: movie._id}, movie, {upsert: true, new: true}, (err, result) => {
return result;
});
} catch(err) {
return err;
}
};
As the findOneAndUpdate doc says, the method without a callback
returns a Query
which has to be executed. So to make the method work it should look like:
exports.updateMovie = async (movie) => {
try {
return await Movie.findOneAndUpdate({_id: movie._id}, movie, {upsert: true, new: true}).exec();
} catch(err) {
return err;
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With