Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda