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

1.7K
Vistas
How to update nested objects in MongoDb with Mongoose

I am trying to update one key value in a nested object in MongoDB. currently, the way I am doing it the entire nested object is being overwritten, how can I change one key-value pair?

  try {
      Files.updateOne(
        { _id: document._id },
        {a:{b:{c:"new text", d: "not to change"}}},
        function (err, result) {
          if (err) {
            res.send(err);
          } else {
            res.send(result);
          }
        }
      );
    } catch (err) {
      res.status(400).send(err);
    }

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try this:

try {
  Files.updateOne(
    { _id: document._id },
    { "a.b.c": "new text" },
    function (err, result) {
      if (err) {
        res.send(err);
      } else {
        res.send(result);
      }
    }
  );
} catch (err) {
  res.status(400).send(err);
}
over 4 years ago · Santiago Trujillo 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