Search code examples
nosqlarangodbaql

Include Entry node in AQL Graph traversal


I'm using AQL to traverse through Graphs, right now that's my statement:

FOR v, e, p IN 1..1 ANY 'Bridges/1004' 
    GRAPH 'S_Graph'
    FILTER not (p.vertices[1].IID != 'null' AND p.vertices[1].cls_name == "Bridge")
    OR p.vertices[1].cls_name == "Node"
    RETURN v

And the result are the Documents my Entry-Document Bridges/1004, but not the Entry-Document itself.

How is it possible to include the Entry-Document in the Query-Result?


Solution

  • Just change the traversal depth from 1..1 to 0..1 and that should include the initial node.

    FOR v, e, p IN 0..1 ANY 'Bridges/1004' 
    GRAPH 'S_Graph'
    FILTER not (p.vertices[1].IID != 'null' AND p.vertices[1].cls_name == "Bridge")
    OR p.vertices[1].cls_name == "Node"
    RETURN v
    

    Also note that in your original query, if you return the path, it does include all the nodes in the path including the original node