Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Returning find result to a variable

I have this function with which I want to find a employee first, ane store it to a variable 'a' and then pass it as an additional field for the aggregate:

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

but I get this error after trying to test it :

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)
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda