Javascript 如何在另一个函数中调用聚合函数?

Javascript 如何在另一个函数中调用聚合函数?,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,我需要返回t2函数中的t1函数数据。我尝试了这个方法,但它说未定义请帮忙:)谢谢 function t1() { db.users.aggregate( [{ $group: { "_id": { "_id": "$_id", "name": "$name",

我需要返回t2函数中的t1函数数据。我尝试了这个方法,但它说未定义请帮忙:)谢谢

function t1() {
        db.users.aggregate(
            [{
                    $group: {
                        "_id": {
                            "_id": "$_id",
                            "name": "$name",
                            "email": "$email"
                        }
                    }
                }

            ],function(err, data) {
                return data;
            }) 

    }

    function t2(req, res, next) {
        var test = testFunction();
    })

您需要将回调从
t2
传递到
t1

function t1(callback) {
    db.users.aggregate(
        [{
                $group: {
                    "_id": {
                        "_id": "$_id",
                        "name": "$name",
                        "email": "$email"
                    }
                }
            }

        ], callback) 

}

function t2(req, res, next) {
    t1(function(err, data) {
        if (err) {
            return res.status(500).send("Internal error occurred.")
        }

        return res.status(200).json(data);
    })
})