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

123
Vistas
Loop custom array from mongoose returned empty

here is my problem

I want to loop data from two entities Project and User, my Project entity have a field with User id called creatorId.

I looped it and tried to add my user data _id, displayname and avatarUrl.

For now that work, but when I send it from the backend to the frontend nothing appears, like the array is empty.

const projectList = [];
  Project.find({}, function(err, projects) {
     projects.map(project => {
      User.findById(project.creatorId, function(err, creator){
        projectList.push({
          _id: project._id,
          title: project.title,
          description: project.description,
          avatarUrl: project.avatarUrl,
          creationDate: project.creationDate,
          projectCreator: {
            _id: creator._id,
            displayname: creator.displayname,
            avatarUrl: creator.avatarUrl
          },
          git: project.git
        })
      })
    })
  });
  res.send(projectList);  

about 4 years ago · Juan Pablo Isaza
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