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

183
Visualizações
Mongoose wont push object with new key: value to an array

I'm using Mongoose with Next.js, I made a model for User with one "page" object, and every time there is any change inside, I just update it as:

xUser.page.array = * the new array *

and it works well, now I made a new option to add something to the array, and it works well as:

xUser.page.array.push({ key1: value1, key2: value2, })

but now i decided to create a new key, "value3" and I'm trying to push it like that:

xUser.page.array.push({ key1: value1, key2: value2, key3: value3})

and after that:

user.markModified('page')
await user.save()

it does save the object inside the array, but without the new key and value ("key3") and when I console.log the memorized array (xUser.page.array) it does show the new key&value in the inserted object, but as I said not in the db as well :/ how can I add the new key&value? thanks!

Critical edit: looks like when i remove one key value from the object and push, for exa { key2: value2, key3: value3 } (without key1/val1) it does work, so somehow its limited to just 2 key values..

about 4 years ago · Juan Pablo Isaza
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