2
votes

I want to pick a node and get all of the nodes that are connected to it by relationship. Even this they are nth degree connections.

What is the py2neo or simply cypher query for this?

1

1 Answers

3
votes

This Cypher query should work (if the picked node has a myId value of 123):

MATCH p=(n { myId:123 })-[*]-()
UNWIND FILTER(x IN NODES(p) WHERE x <> n) AS node
RETURN DISTINCT node;

The FILTER function filters out the picked node, even if there are paths that cycle back to it.