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

115
Views
Mongoose forEach is not a function

I have a database of 50,000 users and I need to loop over each one and update them with some dynamic values per user.

I've tried using

users.find({}).forEach((user) => { console.log('Some code.') })

But it says that forEach is not a function - from research it looks like this is a mongodb function but not a mongoose function.

I've tried using just find({}) but of course the results will be cursor based, and it also doesn't actually console.log anything for me.

I've also tried using .stream(), but that's also returning not a function and I've also tried using .batchSize(100) but that also does not return anything in the console log when testing.

I've looked into updateMany but that is only good for updating the same static value in a field.

I'm a little lost on how to proceed forwards in a performant way. Any ideas?

Thanks,

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The Model.find() function returns a promise, not an array.

You will need to use await or a callback to actually execute the find and retrieve the result array before iterating.

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