Trying to get the value from function like
1. const tempIsEmailExistsInDb = isEmailExistsInDb("sample_email@email.com");
2.
3. const isEmailExistsInDb = usrEmail => {
4. let tempCount;
5. userModel.countDocuments( {"email": usrEmail}, function (err, count){
6. tempCount = count;
7. });
8. // count > 0 if document exists
9. console.log("tempCount", tempCount);
10. return tempCount > 0;
11. };
In this scenario, line 9, 10 and 1 are executing first then only line 6 is executing. Because of this reason, not getting desired value in line 1 and 9
To resolve this, tried to use async
await
but some where i'm doing mistake. Can any one help in this
Edit: Gone through this but some where i'm doing mistake related to mongoDB