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

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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