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

145
Visualizações
What method is used to modified a property from an array of records returned from a Mongoose query?
    const images = await tbl
      .find({
        creator_id: req.user._id,
      })
      .select({
        creator_id: 0,
      })
      .then((images) =>
        images.forEach((image) => {
          image.file_name = process.env.IMAGE_HOST_URL + image.file_name;
        })
      );

The code above fails at the .then bit. What is the proper mongoose method to replace it with to achieve what is intended in the code?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What do you mean fails?

The find returns two objects. An err and res. the .then should be

.then((err, res) => {
    if (err) {...}
    else {
        res.forEach(img => {
           image.file_name = process.env.IMAGE_HOST_URL + image.file_name;
           img.save() 
        })
    }

}) 

You will get a list of documents that match the filter of the find as the res (error object, which should be null, is first). And you must save it after the changes.

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