Angularjs 基于用于身份验证的电子邮件id在平均堆栈web应用程序中从mongodb检索数据

Angularjs 基于用于身份验证的电子邮件id在平均堆栈web应用程序中从mongodb检索数据,angularjs,node.js,mongodb,express,mongoose,Angularjs,Node.js,Mongodb,Express,Mongoose,根据身份验证时使用的电子邮件id从mongodb检索数据时遇到问题。我正在创建一个简单的web应用程序,用户可以在其中捐赠书籍 用户必须首先使用电子邮件和密码凭据登录到应用程序。 当用户捐赠一本书时,数据以以下方式存储在mongodb中名为“books”的表中(angularjs): 这是controller.js文件中的代码: var dbdes= mongojs('books' , ['books']); app.post('/books', function(req, r

根据身份验证时使用的电子邮件id从mongodb检索数据时遇到问题。我正在创建一个简单的web应用程序,用户可以在其中捐赠书籍

用户必须首先使用电子邮件和密码凭据登录到应用程序。 当用户捐赠一本书时,数据以以下方式存储在mongodb中名为“books”的表中(angularjs):

这是controller.js文件中的代码:

    var dbdes= mongojs('books' , ['books']);

    app.post('/books', function(req, res){
        console.log(req.body);
        dbdes.books.insert(req.body, function(err, doc){
            res.json(doc);
        })
    });
    $scope.donate = function(event){
        console.log($scope.don);
        event.preventDefault();
        $http.post('/books', $scope.don).success(function(response){
            console.log(response);
        });
    };
该应用程序有另一个选项卡历史记录。单击历史记录,用户必须能够查看他捐赠的所有书籍的详细信息

历史记录按钮:

<a ng-click=" gethistory('<%= user.local.email %>');" ></span><span class="r">History</a>
}))

controller.js:

    $scope.gethistory = function(email){
    console.log(email);

    $http.get('/books/' + email).success(function(response){
        //this line is printing. but i cant see the details on the web page
        console.log("i got the data requested - history");
        $scope.books = response;
        $scope.y = "";
    })
};

您需要更新“获取书本”功能

app.get('/books/:email', function (req , res){
  var email = req.params.email;
  dbdes.books.find({
    "email": email
  }, function(err,docs){
    console.log(docs);
    res.json(docs);
  });
});

您如何验证您的用户?注册时,用户必须输入存储在表中的电子邮件ID和密码。虽然捐赠用户的emailid完全可以存储在“email”字段下的书籍中。@VaredisIt仍然显示所有条目。我需要根据用户的emailid筛选条目。现在检查答案,以便根据用户的emailid筛选条目。我收到以下错误:TypeError:dbdes.books.find(…).exec不是函数。由于同一个表有两个get函数,所以第二个get函数没有执行。您使用哪个插件进行mongodb连接?我使用的是mongoose。我对问题中的代码做了一些修改。请看一看。
app.get('/books', function (req , res){

dbdes.books.find(function(err,docs){
    console.log(docs);
    res.json(docs);
});
    $scope.gethistory = function(email){
    console.log(email);

    $http.get('/books/' + email).success(function(response){
        //this line is printing. but i cant see the details on the web page
        console.log("i got the data requested - history");
        $scope.books = response;
        $scope.y = "";
    })
};
app.get('/books/:email', function (req , res){
  var email = req.params.email;
  dbdes.books.find({
    "email": email
  }, function(err,docs){
    console.log(docs);
    res.json(docs);
  });
});