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

287
Views
MongoDB: Remove attribute from nested Object Array

I have to remove an attribute from an deep nested object inside an array of objects.
It looks like this:
Array

I want to unset the IndividualAge only for one specific Period Type Past
for one specific Block with the name "HouseKeepingDamageCost", if it exists.
I have to take care, because the other Objects inside Blocks and
other Periods have also an attribute called "IndividualAge", they can stay.
Can someone help me ? I tried it with $elemMatch without success.

Thanks in advance.

Playgorund with my Data & Query: Mongoplayground

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You want to use arrayfilters to do so:

db.collection.update({},
{
  "$unset": {
    "Blocks.$[block].Periods.$[period].IndividualAge": ""
  }
},
{
  "multi": false,
  arrayFilters: [
    {
      "block.Name": "HouseKeepingDamageCost"
    },
    {
      "period.Type": "Past"
    }
  ]
})

Mongo Playground

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!