Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查用户是否';的电子邮件存在于数据库中_Javascript_Angularjs_Node.js_Mongodb_Authentication - Fatal编程技术网

Javascript 检查用户是否';的电子邮件存在于数据库中

Javascript 检查用户是否';的电子邮件存在于数据库中,javascript,angularjs,node.js,mongodb,authentication,Javascript,Angularjs,Node.js,Mongodb,Authentication,我有一个基本的登录表单,想验证数据库中是否存在用户的电子邮件,但不确定angular+节点的语法 Main.js我在运行此功能的submit按钮上单击了ng。我收到来自输入的电子邮件,不知何故需要将其传递给db检查 $scope.logIn = function() { var email = $scope.formInfo.email; $http.get('/findUser').success(function(response){ console.log

我有一个基本的登录表单,想验证数据库中是否存在用户的电子邮件,但不确定angular+节点的语法

Main.js我在运行此功能的submit按钮上单击了ng。我收到来自输入的电子邮件,不知何故需要将其传递给db检查

$scope.logIn = function() {
    var email = $scope.formInfo.email;

    $http.get('/findUser').success(function(response){
        console.log('find user data');
        console.log(response);
    });
};
Server.js我已连接到数据库,但不确定如何与客户端和后端数据建立连接,也不确定语法是什么

app.get('/findUser', function(req, res){
//what do I do here?
    db.rejoin_your_ex.find({ email: 'the user's email' }, function(err, docs){
        res.json(docs);
    });
});

客户端

$scope.logIn = function() {
   var email = $scope.formInfo.email;

   $http({
       url: '/findUser', 
       method: "GET",
       params: {"email": email}
   }).success(function(response){
       console.log('find user data');
       console.log(response);
   });
};
服务器端

$scope.logIn = function() {
   var email = $scope.formInfo.email;

   $http({
       url: '/findUser', 
       method: "GET",
       params: {"email": email}
   }).success(function(response){
       console.log('find user data');
       console.log(response);
   });
};
在后端,您可以使用模块进行mongodb特定的查询

var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/test");
db.bind('user');

app.get('/findUser', function(req, res){
    //what do I do here?
    db.user.find({ email: req.params.email }, function(err, user){
        res.json(user);
    });
});
希望对你有帮助