0
votes

I have a graph in ArangoDB whose root node is 'X'. Now "a,b,c,d,e,f" are the siblings of 'X' direct or grand grand siblings. Now from a given siblings node "a,b,c,d,e or f" I want to get to node 'X'. Is there any general AQL query to traverse directly to the root node of any graph ?

3
Did the answer work for you? if yes, can you mark it 'accepted'? If not, whats missing?dothebart

3 Answers

4
votes

To provide an exact example I would need to know a bit more, but this is one of several solutions.

Assuming that the nodes are connected by "child" edges and the direction of the edges go from parent to child. You would traverse the tree up or INBOUND

FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child RETURN p.vertices

If you know how many hops maximum to the root, change the 50 to that value.

This statement will return all of the paths and intermediate paths from the starting node through the child links to the head node. To return only the path to the head node, you would have to filter out the intermediate paths. This could be done with a check to see that there is no parent vertex.

FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child 
  FILTER LENGTH(EDGES(child,v._id,'inbound'))==0 RETURN p.vertices

which will filter out all paths that do not end at a root vertex.

1
votes

RHSMan's answer helped me but here is cleaned up a bit

LET ref_people = (
    FOR p IN people RETURN p._id
)
LET l = (
     FOR id IN ref_people 
         FOR link IN links FILTER id == link._from RETURN id
)

RETURN MINUS(ref_people, l)
0
votes

I came across this as I had the same problem but the above is outdated:

I did the following:

let ref_items = (for s in skills
return s._id)


let c = (for item in ref_skills
for sk in skill_skill
    filter item == sk._to

    return item)
return MINUS(ref_skills, c)