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

511
Visualizações
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 Respostas
Responde à pergunta

0

Please try this:

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

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