I have asked this question .exec callback using returns is returning undefined, but console.log do have item in it
The answer does work, but it throws .exec away, I have been trying to re-implement it using .exec, however when I console.log something inside the .exec, it does print.
The reason I have been trying to use the .exec way is that a lot of StackOverflow questions use a lot .exec and I think ".exec" will be faster?
When I return it, it returns undefined. What is the cause and how can I solve it while keeping the .exec
let user = await User.findById(paymentBody.user_id)
.populate(User.schedule_table)
.exec((err, foundDocument) => {
console.log(foundDocuments)
return foundDocument;
});
console.log(user)
The code inside .exec (console.log(foundDocuments)), returns the result of query.
However, when I perform console.log(user) after the query, it shows undefined.