Today I will try to share about information how to solved "Solution: Error occurred promise pending in nodejs mongodb" .
Let's see example scripts error resutls :
const va = User.findOne({email: profile?.email})
.then((docs)=>{
//console.log(docs);
return docs;
})
.catch((err)=>{
console.log(err);
});
The above script, results message is something like an error promise pending.
To solve these problems try use async scripts of the first function and don't forget to put await scripts keyword. like the scripts below.
exports.signInGoogle = async function(req, res, next){
try {
const va = await User.findOne({email: profile?.email})
.then((docs)=>{
//console.log(docs);
return docs;
})
.catch((err)=>{
console.log(err);
//res.json({ token: jwt.sign({ email: user.email, fullName: user.fullName, _id: user._id }, 'RESTFULAPIs') });
});
console.log(va);
};
These scripts work for me, and hope work with you too. Thanks for visiting my blog. Hope this blog can helping you.
No comments:
Post a Comment