0
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});
})
4

1 回答 1

0

请更正聚合甲酸盐:

 Model.aggregate([{}]) instead of Model.aggregate({})

使用喜欢:

Club.aggregate([{
                    $group: {
                        _id: "$positioninclub"
                    }
                }], (err, newResult) => {
                   callback(err, newResult) ;
                });
于 2018-05-15T13:07:56.447 回答