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

156
Views
Node Js - Mongo DB - Update Many

Here is an example database I have in mongodb.

[
 {name: "Tommy", age: 12, _id: 12345 },
 {name: "Pat", age: 22, _id: 54321 },
 {name: "Bridie", age: 64, _id: 98765 }
]

How do I update the age of Pat to be 50 and the age of Tommy to be 20 in a single query using updateMany?

Im currently updating them individually in a for loop using this method.

const peopleToBeUpdated = [
    { name: "Pat", age: 50 },
    { name: "Tommy", age: 20 }
]

for (const person of peopleToBeUpdated) {
    try {

        await peopleSchema.updateOne({ name: person.name }, { $set: { age: person.age  }})
   
    } catch (error) {
        
    }
}

Any help is appreciated, thanks..

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!