3

I have a document collection 'node' and an edge collection 'attribute'. I am trying to get all edges in 'attribute' collection from: 'node/582148' to: 'node/582016'.

The simplest AQL query I've been able to devise is the following:

FOR v, e, p IN OUTBOUND 'node/582148' `attribute`
    FILTER e._to == 'node/582016'
    RETURN p

Is there really no way to do this in one, like:

FOR v, e, p IN OUTBOUND 'node/582148' TO 'node/582016' `attribute` RETURN p

It's only possible to use the 'TO' keyword with SHORTEST_PATH. To clarify: I am only interested in direct paths (1 edge) between the nodes

thanks

zra
  • 141
  • 1
  • 13

1 Answers1

3

Using graph traversal i would recommend to use the following AQL query to get all outgoing edges, which is filtering by the target vertex key:

FOR v, e IN OUTBOUND 'node/582148' `attribute`
FILTER v._key == '582016'
RETURN e

Another approach is to address the edge as a document with attributes _from and _to without graph traversal:

FOR e IN `attribute`
FILTER e._from == 'node/582148' && e._to == 'node/582016'
RETURN e
  • thanks. in the first example, what if **v** is not of type 'node', shouldn't I add FILTER v._key == 'node/582016'? – zra Oct 24 '17 at 12:35
  • 1
    No, v._key should only contain the key of the document, not its collection name. – Maximilian Kernbach Oct 24 '17 at 15:27
  • `_key` stores the document key only, e.g. `"1234"`. Document keys are not even allowed to contain slashes: https://docs.arangodb.com/3.2/Manual/DataModeling/NamingConventions/DocumentKeys.html `_id` is a concatenation of collection name, a forward slash and the document key, e.g. `"node/1234"`. – CodeManX Dec 10 '17 at 07:10
  • Regarding the Traversal... Do you think there is any way how to further optimize such a query? When I am using depth of 1..5 my query takes around 28sec with 9 vertices collections and 16 edge collections, with only 11764 objects in total (entities+links). I know finding all paths between 2 nodes is complex task, but I am looking for any optimization I could make. In further project I will need depth even like 5..10 which will be even more complex. – Dominik Franek Dec 04 '18 at 09:48
  • @DominikFranek I suspect the new PRUNE function (new in 3.5?) will help you in the traversal case. See: https://www.youtube.com/watch?v=4LVeeC0ciCQ – Dave Mar 01 '20 at 00:40