我想得到一个像下面这样的对象,这样我就可以将它们传递给我的 Dust.js 模板。
{ officers:
[ { _id: '543dcbcf846c139cc042c813', name: 'Alpha' },
{ _id: '543dcc25846c139cc042c814', name: 'Beta' },
{ _id: '543dcd91846c139cc042c815', name: 'Gamma' } ],
branches:
[ { _id: '543dcbcf846c139cc042c813', name: 'Alpha' },
{ _id: '543dcc25846c139cc042c814', name: 'Beta' },
{ _id: '543dcd91846c139cc042c815', name: 'Gamma' } ] }
这是我在控制器中使用 Mongoose 获取文档并将它们组合起来的代码。我总是收到错误 500,我的代码有什么问题吗?
var Officers = require('../../models/officers');
var Branches = require('../../models/branches');
router.get('/create', function (req, res) {
async.parallel({
officers: function(cb){
Officers.find({}, '_id name', cb);
},
branches: function(cb){
Branches.find({}, '_id name', cb);
}
}, function(err, results){
res.render('companies/create', results);
});
});