For a given node n, I want to get its related nodes and all nodes connected to the related nodes. For example:
MATCH (n)-[:IN]->(x)
WHERE n.myid='myid'
RETURN n, x
How do I return all the x's connected nodes as well?
Assuming that you don't want type(r) to be IN
,
Have you tried?
MATCH (n)-[:IN]->(x)-[]-(y)
WHERE n.myid='myid'
AND y<>n
RETURN n,x,collect(y)
I have it collecting y because you will otherwise get a bunch of "rows" for each, but that is totally up to you.
Try playing on: http://console.neo4j.org
Console with above example http://console.neo4j.org/r/yaczrx
Also, you may want to look into how deep you want that second lookup to go.
BTW: if you want to see the path in the console (you can see how the nodes are interconnected): http://console.neo4j.org/r/39mz9a
MATCH path =(n:Crew)-[:KNOWS]-m-[rr]-(x)
WHERE n.name='Neo' AND x<>n
RETURN n AS Initial_Node, m AS Linking_Node,
collect(x) AS Nodes_connected_to_Linking_Node, path