【发布时间】:2018-05-15 21:07:56
【问题描述】:
function(callback){
Club.aggregate({
$group: {
_id: "$positioninclub"
}
}, (err, newResult) => {
callback(err, newResult) ;
});
},
我的代码在这部分有问题...我正在尝试将此代码添加到异步模块的并行方法中。
router.get('/',ensureAuthentication,function(req,res){
async.parallel([
function(callback){
//find function return the array
Club.find({},(err,result) => {
callback(err,result);
});
},
function(callback){
Club.aggregate({
$group: {
_id: "$positioninclub"
}
}, (err, newResult) => {
callback(err, newResult) ;
});
},
],(err,results) => {
const resl = results[0];
const resl1 = results[1];
console.log(resl);
const dataChunk = [];
const chunkSize = 3;
for(let i = 0;i < resl.length ; i = i + chunkSize){
dataChunk.push(resl.slice(i,i+chunkSize));
}
console.log(dataChunk);
res.render('dashboard', {title: 'Portal', resl: resl});
})
【问题讨论】:
-
这里出了点问题。这真的是猫鼬吗?如果是这样,那么
Model.find()应该始终返回一个数组,即使没有结果也是如此。如果没有length属性,则返回不同的东西。如果它不是猫鼬而只是基本驱动程序,那么这些方法实际上不会返回数组,这可以解释它。那么您实际使用的是哪个驱动程序?