//Using callback
const tempIsEmailExistsInDb = isEmailExistsInDb("[email protected]", function(res) {
if (res) {//do something
}
});
const isEmailExistsInDb = (usrEmail, cb) => {
let tempCount;
userModel.countDocuments( {"email": usrEmail}, function (err, count){
tempCount = count;
cb((tempCount > 0))
});
};
Also for using async
method
router.get('/' , async (req, res) => {
const isEmail = await isEmailExistsInDb("[email protected]");
if (isEmail > 0) {
}
})
const isEmailExistsInDb = async (usrEmail, cb) => {
let tempCount = await userModel.countDocuments( {"email": usrEmail});
return tempCount;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…