0
votes

I have a situation where a node has outward relationships to multiple nodes. These children in turn can have outward and inward relationship to other nodes until you reach the leaf nodes.

Is there a good way to write a cypher query where based on a starting node, I can traverse to the nodes children, then to their related (inward and outward) nodes and so on until I reach the leaves. The result should return all the relationships and nodes found. Thanks in advance.

1

1 Answers

0
votes

Maybe this is too greedy but you can try

START a=node(id) //replace with the id of the node you want to start 
MATCH p=a-[r*]->x //get all the paths to all nodes
WHERE NOT(x-->()) //exclude nodes with Direction Out Relationships
RETURN p,a,x,r //return whatever you need