无法在我的Jade页面上显示Mongodb的值

时间:2016-01-22 17:05:07

标签: node.js mongodb express pug

我有以下路线:

app.get('/dashboard', passportConf.isAuthenticated, userController.getBoardsCount,userController.getSharedBoardsCount, userController.getBoards);

这是我用来从MongoDB获取值的中间件代码:

exports.getBoardsCount = function(req, res, next) {
    var count = 0;
    Room.count({
        "owner": req.user._id
    }, function(err, count) {
        if (err) {
            console.log(err);
        }
        if (count) {
            req.count = count;
        }
        next();
        console.log(count);
    })
};

exports.getSharedBoardsCount = function(req, res, next) {
    var sharedBoards = 0;
    Room.count({
        $and: [{"owner": {$ne: req.user._id}},{ users : req.user._id}]
    }, function(err, sharedBoards) {
        if (err) {
            console.log(err);
        }
        if (sharedBoards) {
            req.sharedBoards = sharedBoards;
        }
        next();
        console.log(sharedBoards);
    })
};

我可以使用count在我的jade文件上显示#{count},但sharedBoards虽然显示在终端中但未显示。我使用#{sharedBoards}在我的Jade文件中显示它。你能帮帮我吗?我似乎无法找到问题所在。

1 个答案:

答案 0 :(得分:0)

exports.getBoards = function(req, res) {

Room.find({
    users: req.user._id
}, function(
    err,
    rooms) {
    if (err) {
        return err;
    }


        res.render('account/dashboard', {
            rooms: rooms,
                            count:req.count,
                            sharedBoards:req.sharedBoards
        });

});

 };

我拼错了sharedBoards。