简体   繁体   English

在Neo4j中使用密码进行遍历

[英]Traversing using cypher in Neo4j

I have a situation where a node has outward relationships to multiple nodes. 我遇到一个节点与多个节点具有向外关系的情况。 These children in turn can have outward and inward relationship to other nodes until you reach the leaf nodes. 这些子级继而可以与其他节点具有向外和向内的关系,直到您到达叶节点为止。

Is there a good way to write a cypher query where based on a starting node, I can traverse to the nodes children, then to their related (inward and outward) nodes and so on until I reach the leaves. 有没有一种写密码查询的好方法,其中可以基于起始节点遍历节点子节点,然后遍历它们的相关节点(向内和向外),依此类推,直到到达叶子为止。 The result should return all the relationships and nodes found. 结果应返回找到的所有关系和节点。 Thanks in advance. 提前致谢。

Maybe this is too greedy but you can try 也许这太贪婪了,但您可以尝试

START a=node(id) //replace with the id of the node you want to start 
MATCH p=a-[r*]->x //get all the paths to all nodes
WHERE NOT(x-->()) //exclude nodes with Direction Out Relationships
RETURN p,a,x,r //return whatever you need

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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