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

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