Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!