Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j Cypher获取循环链表中的所有节点_Neo4j_Cypher - Fatal编程技术网

Neo4j Cypher获取循环链表中的所有节点

Neo4j Cypher获取循环链表中的所有节点,neo4j,cypher,Neo4j,Cypher,我有一张像这样的图 (user)->[:Comments]->(comment)->[:Comments]->(comment)->[:Comments]->(comment)->(user) 基本上,这是一个循环链接列表的评论,用户已作出。该列表循环并最终返回到用户。我如何使用cypher检索所有评论?尝试了一下,我觉得它有点复杂,但不管怎样,它就在这里 假设从最后一条注释到用户的关系为:Comments i、 e而不是。->(注释)->(用户) 我

我有一张像这样的图

(user)->[:Comments]->(comment)->[:Comments]->(comment)->[:Comments]->(comment)->(user)

基本上,这是一个循环链接列表的评论,用户已作出。该列表循环并最终返回到用户。我如何使用cypher检索所有评论?

尝试了一下,我觉得它有点复杂,但不管怎样,它就在这里

假设从最后一条注释到用户的关系为:Comments

i、 e而不是
。->(注释)->(用户)

我假设
。->(注释)-[:注释]->(用户)

START n=节点(1)
匹配n-[:注释*0..]>(c)
中国在哪里
使用collect(c)作为所有注释,n
将last(allComments)作为lastcoment,n,allComments
其中lastcomment-[:Comments]->n
返回所有评论
我必须把cn放在哪里,因为最后一条评论->用户关系是评论。如果是其他内容,最好不要使用它(它只是用来选择链中的最后一条评论)。它还返回一个集合


Bet@Wes Freeman有一个更漂亮的解决方案

Nice,为什么控制台中的结果会返回用户?我把你的结果编辑成这样:它有你的心脏,但不会返回用户。好问题,让我回到我的,检查用户为什么回来,没有注意到。您发布的控制台示例是我的第一次尝试,但问题是您还将获得未连接到原始用户的最后一条注释的链。如果可以的话,那么你不需要我的所有额外的东西(基本上是建立最后的链接回来)愚蠢的错误…我在那里有深度0,更改为匹配n-[:Comments*1..]>c,它将排除用户谢谢,我不需要用户(因为我将返回他)+从我这里得到1。干杯
START n=node(1) 
MATCH n-[:Comments*0..]->(c) 
WHERE c<>n 
WITH collect(c) AS allComments,n 
WITH last(allComments) AS lastcomment,n,allComments 
WHERE lastcomment-[:Comments]->n 
RETURN allComments