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

275
Views
How to update properties of object in array in mongoose

I've a collection which elements all contain array of objects, I want to update some properties of certain object. There is the collection:

{
    _id:'a45ea2',
    array: [
        {
            _id: '3fa5ce'
            property: 'qwe'
        },
        {
            _id: '5f5f1b'
            property: 'asd'
        },
    ]
}
{
    _id:'cd7114',
    array: [
        {
            _id: '27f580'
            property: 'qwe'
        },
        {
            _id: '2f33dd'
            property: 'asd'
        },
    ]
}

e.g. wanna update obj named _id with property 5f5f1b to property 000000

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use update and arrayFilters like this

db.collection.update({},
{
  $set: {
    "array.$[elem].property": "00000"
  }
},
{
  arrayFilters: [
    {
      "elem._id": "5f5f1b"
    }
  ]
})

https://mongoplayground.net/p/OIGVr5HWhr9

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