简体   繁体   中英

Neo4J Cypher - Unwinding nodes from a path variable

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.

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

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;
MATCH p = allShortestPaths((a: person)-[:PARENT_OF]-(b: person))
with nodes(p) as nodes
with nodes[size(nodes)-1] as b
return b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM