搜索所有节点都与同一节点有关系的路径
Search paths where all nodes are in a relationship with same node
以下图为例:我正在尝试确定所有 Persons are_sons 的 人 所有 出生 在同一个国家:
是否有使用 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
这应该 return 一个列表或记录,每个列表包含一个人,他的所有 parents 都出生在美国
以下图为例:我正在尝试确定所有 Persons are_sons 的 人 所有 出生 在同一个国家:
是否有使用 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
这应该 return 一个列表或记录,每个列表包含一个人,他的所有 parents 都出生在美国