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

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

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