快递获取 api

Express Get api

我现在正在练习 MEAN 堆栈。

我用 Angular shell 做了一个项目,我在我的项目中包含了 express。

这是我的第一个 GET,我想用它从我的 mongoDB 中检索一些数据,在本例中是整个集合:

 router.get('/biscottigrazie', function(req, res) {
    var db = req.db;
    var collection = db.get('biscotti');

});

也许我错过了这个概念,但我认为从 angular 我应该能够 "call" 这个 GET 并获取数据。

所以,我的 var 集合应该包含数据,我如何从 angular 文件中检索它们?

您不会从请求变量中获取数据库实例。您将在定义数据库时获得它。

var db = new Db('test', new Server('localhost', 27017));

router.get('/biscottigrazie', function(req, res) {
    var collection = db.getCollection('biscotti');
    res.send(collection);
});