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

167
Views
How to get user using forEach loop Mongoose

I have an array of IDs looks like

get profiles [ '62d80ece61a85d738fa0c297', '62d80fb061a85d738fa0c29c' ]

I want to loop this array and every index use it in find() method My code looks like

let total = [];

profile.forEach(async (index) => {
      console.log('index', index);

//OUtput of the console of index 
//index 62d80ece61a85d738fa0c297
//index 62d80fb061a85d738fa0c29c

      let user = await this.userModel.findOne({ _id: index });
      total.push(user);
 console.log('Service', total);
//Output of service is Service []

Thanks in advance

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Without any information about the schema one solution that I can propose is explicit convert the string to ObjectId

about 4 years ago · Santiago Gelvez Report
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!