How to efficiently update this deep-nested array?

Hello… everyone.
I will try to reproduce a MRE, let me know if you need any more examples.

First of all, we have a collection, where documents are holding a data like this:

[
  {
    ....
    children: {
      ....
      children: {
        ....
        children: {
          ....
          children: [
            {
              ....
              children: [Array],
              ....
            }
          ],
          ....
        },
        ....
      },
      ....
    },
    ....
  }
]

Nothing extra ordinary, just document-within-document. Problem is, we dont know the maximum depth. We dont know how many childrens an object has.

Now, question is, how can i efficiently update an object, lets say at 60th depth?

For update i was thinking:

  • Pull everything

  • Do a DFS based on the ID

  • Update the found dictionary

  • Replace the dictionary with the original, which, creates an overhead already.

  • And update the whole root with the changed children.

I am already doing the first two for finding a data inside the array. It works pretty well, but I feel like doing this for updating feels horribly wrong and not scalable.

I am finding data with DFS by returning a path list for it, for example, in my Python application, I pull the
entire array from the root, and when I calculate DFS, it returns;

[0,4,2]

indicating that searched children is in

root.children.0.children.4.children.2

so i can pull the data with, lets say:

something = root.children[0].children[4].children[2]

It is nice, and works well in Python.

And uh, I cant build dot notation for query. dot notation is not working beyond the first depth. so i am just stuck in

root.children.0

what can i do?

*No I cannot change the data structure by any means. Any advices besides that is beyond welcome <3