0
votes

I have seen examples of unwinding lists, but not of unwinding a list of paths. How can I find, for example, all of the shortest paths between one type of node and another, and return or get the nodes that are found, in this example the nodes specifically being b.

MATCH p = allShortestPaths((a: person)-[:PARENT_OF]-(b: person))
UNWIND nodes(p) ... //get all of the b nodes
RETURN b

Note: I would like to use b within the query for another purpose (omitted), and therefore need to unwind the path into a list of b nodes.

3

3 Answers

0
votes

After matching all shortest paths, if you just want the b nodes as a result, you may simply RETURN b. I don't believe you need to UNWIND it, since b is clearly identified in your MATCH

Edit:

MATCH p = allShortestPaths((a: person)-[:PARENT_OF]-(b: person))
WITH collect(b) as bees
UNWIND bees as b
//do something
return b
0
votes

It seems like you just want to see all person nodes that have an incoming PARENT_OF node from another person node. If so, this should work:

MATCH ()-[:PARENT_OF]->(b:person)
RETURN DISTINCT b;
0
votes
MATCH p = allShortestPaths((a: person)-[:PARENT_OF]-(b: person))
with nodes(p) as nodes
with nodes[size(nodes)-1] as b
return b