login() {
return new Promise((resolve, reject) => {
userCollection.findOne({email: this.data.email}).then((myUser)=>{
if (myUser && myUser.password == this.data.password) {
resolve("Congrats! Successfully logged in");
} else{
reject("Login failed");
}
}).catch(()=>{
reject("Please try again later")
})
})
}
This is my model and I can use it to find data from Mongodb. I'm using express js. But, I want to know how I can use async
await
to do exactly the same thing that the above promise does. I mean, I would like to convert this code to async
await
way.
Any assistance would be highly appreciated.