Extract list of Nodes and Labels from path

Hi @marcos.stival,
Welcome to the community!

What you're looking for is a way to flatten your list of lists, and then unwind (or pivot them).

MATCH p = (n:Client)-[r:PARENT_OF*]->(t:Client) 
WHERE n.Code="MYCODE"
// nodes(p) is an array of arrays. the reduce is similar to a flat function.
WITH reduce(output = [], n IN nodes(p) | output + n ) as nodeCollection
// here we take the single row of the flattened array and pivot it to rows.
UNWIND nodeCollection as client
// once we have each client in it's own row, then we call labels 
// Also don't forget the distinct! 
// Remember the arrays simply flatten out each path, 2 of your nodes show up in multiple paths.
RETURN distinct client, labels(client)

I hope that was informative while also helping answer the question.
If you have any other follow on questions, let me know :slight_smile:

-Mike

2 Likes