将查找结果返回给变量

时间:2017-04-25 23:06:05

标签: node.js mongodb mongoose

我有这个功能,我想先找一个员工,把它存放到一个变量' a'然后将其作为聚合的附加字段传递:

module.exports.getEmployeeByIde = function(ide, callback){


    let a = Employee.findOne( {managerId: parseInt(ide) } );
    Employee.aggregate([
        { "$match": { id: parseInt(ide) } },
        { $limit: 1 },
        {
            $addFields: { "manager": a }
        },
        {
            "$lookup": {
                "from": "employees",
                "localField": "id",
                "foreignField": "managerId",
                "as": "reports"
            }
            }]
    ).exec(callback);
}

但是在尝试测试之后我收到了这个错误:

Error: cyclic dependency detected
    at serializeObject (C:\bookstore\node_modules\bson\lib\bson\parser\serializer.js:296:33)
    at serializeInto (C:\bookstore\node_modules\bson\lib\bson\parser\serializer.js:776:17)

0 个答案:

没有答案