繁体   English   中英

Neo4j密码:在深度2查找节点,没有圆形路径

[英]Neo4j cypher: find node at detph 2, without circular path

我想找到距离当前节点2的所有节点:

eg:
1<->2
2<->3
1->3
2->4

来自节点1的这种A应该找到节点4

我已经尝试过此查询,但是它遇到了循环路径:

start n=node({startid})
match n--> m
with distinct m as f1
match f1-->m
with distinct m as f2
return count(f2)

实际上,它还在距离2处找到了1,2,3,4作为节点,而没有考虑距离1应该在距离0、2,3距离1上,而只有4在距离2处。

有什么建议吗?

您的意思是这样的吗:

START n=node({startid})
MATCH (n)-[*..2]->m
RETURN m

*之后,您可以定义路径的长度。 * .. 2表示:长度在零到2之间。

START n=node({startid})
MATCH (n)-[*2]->m
WHERE n <> m
RETURN m

对于固定长度2,WHERE将确保不返回n。

有关完整的文档,请访问: http : //docs.neo4j.org/chunked/milestone/query-match.html#match-variable-length-relationships

暂无
暂无

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

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