grapharangodbaql

How can I find edge distance between vertices in ArangoDB using AQL


I have many vertices in ArangoDB which are connected with edges. I need to find the edge between two vertices which can be at any place connected in the graph.


Solution

  • You can use the Shortest Path path search algorithm to find a connection between the two vertices, with this connection having the lowest possible depth.

    It emits the vertices and optionally edges, but for determining the edge distance, all you need is to count how many vertices are emitted and subtract 1:

    RETURN LENGTH(
      FOR v IN ANY SHORTEST_PATH "components/B1" TO "components/B10"
        GRAPH "connectedComponentsGraph" // example graph
        RETURN true // we only need the number of results
    ) - 1