3

I have 2 collections:

  • root - vertices
  • root_edges - edges

Each root_edge connects 2 root documents. I want to be able to make a query so that it will return nested data structure representing the data tree.

I want something like this:

A: {
    id: <int>,
    name: <string>
    B: {
        id: <int>,
        name: <string>,
        C: {
            id: <int>,
            name: <string>
        },
        D: {
            id: <int>,
            name: <string>
        }
    }
    E: {
        id: <int>,
        name: <string>,
        F: {
            id: <int>,
            name: <string>
        }
    }
}

I don't know how many levels can be there, so I need a flexible solution. What I have now produces a flat list of all edges and/or vertices.

kuza
  • 2,761
  • 3
  • 22
  • 56
Quba
  • 4,776
  • 7
  • 34
  • 60
  • You said: “What I have now produces a flat list of all edges and/or vertices”, what query do you mean? And if I understood you correctly, your graph is actually a tree. I mean all of your nodes are connected in a way that they are all formally a tree nodes. Am I right? – kuza Feb 28 '18 at 19:28
  • If you have a lot of data, you would return one gigantic document - that doesn't sound good to me; Traverse the graph and use a cursor to handle the data, and build the structure on the client side – Tom Regner Nov 18 '22 at 09:42

0 Answers0