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 functionality is part of my model designed to retrieve data from Mongodb. Implemented using express js. I'm exploring the possibility of refactoring this code to utilize async
and await
for achieving the same result as with promises.
Guidance on implementing this modification would be greatly appreciated.