Search code examples
arangodbsubgraph

Getting sub-graph result in ArangoDb


I'm using ArangoDB of the respective release series: 3.1

Mode: Single-Server

On this operating system: Windows, version: 10

Kindly ask to know how to get a sub-graph result for a query in ArangoDb?

For example: If I have students nodes linked to a university node by (studyAt) edge and I need to see only the students that have ages > 21, so I need to see a sub-graph that contain only these students linked to the university node.


Solution

  • For this use case you can use an AQL graph traversal starting at your university node with depth 1. Applying the filter age > 21 on the first level vertices will make sure that only students with an age value > 21 are returned.

    The following AQL query is a draft, which has to be adjusted using your variable names.

    FOR v, e, p IN 1..1 ANY 'universityCollection/universityNode' GRAPH 'yourGraph'
      FILTER p.vertices[1].age > 21
      RETURN v
    

    After executing this query in the web interface the result is shown as JSON and graph and the sub-graph result can be downloaded as a JSON file.

    Further information on how to use graph traversals can be found in the AQL documentation.