0
votes

I'm using neo4j to develop a proof of concept and I want to get all Nodes ID for all paths from my root node to leafs, example with ids :

ROOT1-->N1--->SN2--->L1
ROOT1-->N2--->SN3--->L3

What I want to get in my result query is : ROO1,N1,SN2 and ROOT1,N2,SN3

Im new to cypher and I struggle to get this result, any help would be usefull .

1

1 Answers

5
votes

I assume that the ID that you mention is an id property.

To get a collection of the node ids in each full path (except for the leaf node):

MATCH p=(root {id: 'ROOT1'})-[*]->(leaf)
WHERE NOT (leaf)-->()
RETURN EXTRACT(x IN NODES(p)[..-1] | x.id) AS result;

Here is a sample result:

+----------------------+
| result               |
+----------------------+
| ["ROOT1","N1","SN2"] |
| ["ROOT1","N2","SN3"] |
+----------------------+