我正在尝试检查用户是否已经存在于数据库中。我正在使用javascript函数从客户端发送用户的电子邮件ID到节点js路由。路由应查找数据库中是否存在用户。但是所有结果都为空。
/* this is the route*/
router.route('/checkUserInDatabase:email')
.get(async(req,res)=>{
const user = await User.findOne({ 'email': req.params.email });
console.log(user);
});
/* this is the client side function*/
function checkifEmailExists(x){
$.get('/users/checkUserInDatabase:'+ x , function(data, status){
if(data=='true'){
alert('email exists');
}
if(data=='false'){
alert('email does not exist');
}
});
}
慕婉清6462132
开心每一天1111
相关分类