所以我尝试在用户登录后将数据从两个数据库传递到我的仪表板视图,但是...
router.get("/dashboard", middleware.isLoggedIn, function (req, res) {
async.parallel([
function (callback) {
callback(null, User.findById(req.user));
},
function (callback) {
callback(null, Instrument.find({}));
}
],
function (err, results) {
res.send("all good" + results);
console.log(results)
});
});
答案 0 :(得分:0)
试试这样:
router.get("/dashboard", middleware.isLoggedIn, function (req, res) {
async.parallel([User.findById(req.user), Instrument.find({})
],
function (err, results) {
if (err) {
// handle error here
} else {
// results[0] will have user object
// results[1] will have instrument object
res.send(results); // sending json to client
}
});
});