[英]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
.例如,我如何找到一种类型的节点和另一种类型之间的所有最短路径,并返回或获取找到的节点,在本例中,节点特别是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.注意:我想在查询中使用 b 用于其他目的(省略),因此需要将路径展开为b
节点列表。
After matching all shortest paths, if you just want the b
nodes as a result, you may simply RETURN b
.匹配所有最短路径后,如果您只想要b
节点作为结果,您可以简单地RETURN b
。 I don't believe you need to UNWIND it, since b
is clearly identified in your MATCH我不认为你需要解开它,因为b
在你的 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.好像你只是想看到所有person
有来电节点PARENT_OF
从另一个节点person
节点。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.