Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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 搜索所有节点与同一节点处于关系中的路径_Neo4j_Cypher - Fatal编程技术网

Neo4j 搜索所有节点与同一节点处于关系中的路径

Neo4j 搜索所有节点与同一节点处于关系中的路径,neo4j,cypher,Neo4j,Cypher,以下图为例:我试图确定所有人哪些是人的儿子,所有人都出生在同一个国家: 有没有一种优雅的方法可以通过Cypher实现这一点?类似的方法如何 match (c:Country) with c MATCH (kid:Person)-[:IS_SON]-(par:Person) WITH c,kid, collect(distinct par) as parents match (kid) where all(x in parents WHERE (x)-[:WAS_BORN]-(c)) retu

以下图为例:我试图确定所有哪些的儿子,所有人都出生在同一个国家:


有没有一种优雅的方法可以通过Cypher实现这一点?

类似的方法如何

match (c:Country)
with c
MATCH (kid:Person)-[:IS_SON]-(par:Person)
WITH c,kid, collect(distinct par) as parents
match (kid)
where all(x in parents WHERE  (x)-[:WAS_BORN]-(c))
return c, collect(kid) as kids

这将返回一个列表或记录,每个列表或记录都包含一个人,他的父母都出生在美国。我想要的是Ann被归还,因为她的父母都出生在美国。这不会有什么帮助,对吧?误读问题并更新答案以反映你的评论(我希望):)这是有帮助的。但是我不想把查询限制在美国。这张图片只是一个例子。更新了答案,返回了一个国家和在那里出生的孩子的列表