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

157
Views
Mongoose update nested objects on multiple documents

Here is the schema:

var user = new Schema ({
    name: {type:String},
    lastName:  {type:String},
    extraInfo: {
        phone: {type:String},
        age: {type: Number}
    },
    postalCode: {type:Number}
})

Let's assume we have 10 documents with that schema and 5 of them have postalCode '12345'.

How can I select all of them and update the extraInfo.phone and extraInfo.age of these documents?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Well, i dont have a database at hand, to try it out, but it should be something like this.

db.User.update(
    {postalCode: 12345}, 
    {"extraInfo.phone": value1, "extraInfo.age": value2},
    {multi: true});
over 4 years ago · Santiago Trujillo Report
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!