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

153
Views
Mongoose: Update parent on child update

Is there a way to update all associated nested parents on child update? I'm creating a multi-level navbar. The first nested items display without any issues. However, all items 2+ levels deep don't update. I believe this is the problem:

A
|
|_B
  |
  |_C

A knows that B exists. B knows that C exists. But A doesn't know that C exists.

This is the schema:

const DocumentSchema = new Schema({
  name: { type: String, },
  subdocument: [this],
});

This is the returned data in mongodb:

A:

{
name: 'A'
_id:613bd8b351b6f2ba33d229e8
subdocument: 
    {
     name: 'B'
     _id: 613bd8b651b6f2ba33d229ef
     subdocument: {[]}
    }
}

B:

{
name: 'B'
_id: 613bd8b651b6f2ba33d229ef
subdocument: 
    {
     name: 'C'
     _id: 613bd8bc51b6f2ba33d229f5
     subdocument: {[]}
    }
}

C:

{
name: 'C'
_id: 613bd8bc51b6f2ba33d229f5
subdocument: {[]}
}

I'm trying to accomplish this (but for an unknown depth):

A:

{
name: 'A'
_id:613bd8b351b6f2ba33d229e8
subdocument: 
    {
     name: 'B'
     _id: 613bd8b651b6f2ba33d229ef
     subdocument: {
                  name: 'C'
                  _id: 613bd8bc51b6f2ba33d229f5
                  subdocument: {[]}
                  }
    }
}

How would I go about updating mongoDB so that the parent and all the children are updated to reflect the correct information? Thank you so much!

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!