Main.aggregate([
            {$match: query},
            {
                $group: {
                    _id: queryGroupBy,
                    activated: {$sum: '$activated'},
                    componentTitle: {$first: '$componentTitle'},
                    titlePrefix: {$first: '$titlePrefix'},
                    operator_name: {$first: '$operator_name'}
                }
            },
            {
                $project: {
                    _id: '$_id',
                    summation: '$activated',
                    componentTitle: '$componentTitle',
                    titlePrefix: '$titlePrefix',
                    operator_name: '$operator_name'
                }
            }
        ],
        function (err, results) {
            Main.populate(results, { "path": "operator_name" }, function (err, results) {
                if (err) throw err;
                console.log(JSON.stringify(results, undefined, 4));
                console.log('good');
                return res.send(results);
            });

        });
所有评论
加载评论 ...
发表评论