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

103
Vistas
Delay when updating document (MongoDB/Mongoose)

In my application, I am attempting to update a object nested in an array as a below. When testing in postman, there is a delay causing me to have to make two requests in order to see the updated value.

if (taskStatus) {
    const taskStatusNew = await Board.findOneAndUpdate(
      {
        "columns.tasks._id": req.params.id,
      },
      {
        $set: {
          "columns.$[].tasks.$[t]": req.body,
        },
      },
      {
        arrayFilters: [
          {
            "t._id": req.params.id,
          },
        ],
      }
    );
    res.status(200).json(taskStatusNew);
  }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

By default, findOneAndUpdate() returns the document as it was before the update was applied. So you have to set the new option to true if you are using mongoose.

const taskStatusNew = await Board.findOneAndUpdate(
      {
        "columns.tasks._id": req.params.id,
      },
      {
        $set: {
          "columns.$[].tasks.$[t]": req.body,
        },
      },
      {
        arrayFilters: [
          {
            "t._id": req.params.id,
          },
        ],
        new: true
      }
    );

Documentation article for reference: https://mongoosejs.com/docs/tutorials/findoneandupdate.html

about 4 years ago · Juan Pablo Isaza Denunciar

0

If your question is like to return the updated value then use this,- {returnDocument: 'after'}, you just need to add this in other parameter, then it will give you updated value.

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