Is there a way to update all associated nested parents on child update? I’m creating a multi-level navbar like Notion in React. 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
When C is added, 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!