When I use mongoose functions, such as find, save, updateOne ect..
What is the best practice to return a obj/success/failure?
untill now I returned a new promise, but maybe there is a built in functionallity?
example code I use untill now:
function updatePost(name) {
return new Promise((resolve, reject) => {
mongooseModel.updateOne({_id: id}, {title: title,author: author,body: body}, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
so I thought maybe mongooseModel.updateOne
is a promise by itself that can return this error/success without my new promise.
and if not, what is the bast practice to do something like that?