Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda