Search code examples
arangodbarangojs

How to build a route from point "A" to point "E" with the condition that the end point is the point "E"?


I need to build all possible routes from point "A" to point "E" with the condition that the end point is a point "B"

Task example:

From : A, To: B

Example result:

A -> E

A -> B -> E

A -> C -> D -> E

A -> B -> C -> D -> E

So far I was able to do so:

FOR v, e, p IN 1..10 OUTBOUND "city/907499" GRAPH 'CityToCity' 
  FILTER p.edges[*].user ALL == "6609844"
  FILTER p.vertices[4]._id == "city/1012911"
RETURN p

But in this example, you must explicitly indicate at what level the endpoint should be located. How to make it simple from A to E without specifying level 4 in this filter "p.vertices [4] ._ id" ???


Solution

  • As the AQL documentation says:

    // access last array element
    u.friends[-1]
    

    So in your example, specify the constraint on p.vertices[-1]._id

    Also specify a very large number for MAX. Unfortunately, currently AQL requires that a specific value be given, but a ridiculously large value can be specified.