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

512
Vistas
Mongoose how do we update nested objects

I am trying to update nested object using mongoose. I am trying to update the "remindTime date" only and keep the "time" I can update the "remindTime date" however it erases my "remindTime time" property.

I have try the following and none of them work

Model.updateMany(req.query, { remindTime: { date: "2021-09-28" } })

Model.updateMany(req.query, { remindTime: $set:{ { date: "2021-09-28" } } } )

Database data that I am updating

{
    "_id": {
        "$oid": "614d3cedfb2600340fdb28f9"
    },
    "date": "2021-09-23",
    "title": "First test",
    "description": "not working yet",
    "remindTime": {
        "date": "2021-09-28",
        "time": "01:20 am"
    },
    "isComplete": false,
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Please try this:

Model.updateMany(req.query, { "remindTime.date": "2021-09-28"})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use dot notation:

According to docs:

MongoDB uses the dot notation to access the elements of an array and to access the fields of an embedded document.

To specify or access a field of an embedded document with dot notation, concatenate the embedded document name with the dot (.) and the field name, and enclose in quotes:

"<embedded document>.<field>"

So the query:

Model.updateMany(req.query,
{
  "$set": {
    "remindTime.date": "new date"
  }
})

Example here

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