Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!