如何使用 neo4j 密码匹配路径,以防部分路径不存在 return 其余部分

How to match a path using neo4j cypher and in case part of it doesn't exist return the rest

我有一个看起来像这样的 Neo4j 图表:(person:Person)-[:acted_in]->(movie:Movie)-[:played_in]->(country :国家)

我想使用此查询匹配整个路径:

MATCH path = ((person:Person)-[:acted_in]->(movie:Movie)-[:played_in]->(country:Country)) RETURN NODES(path), RELATIONSHIPS(path)

但是,这是棘手的部分,我还想添加一个条件,如果 [:played_in] 不存在,只需 return 部分路径:(person:Person)-[: acted_in]->(电影:电影)

谢谢。

也许类似以下查询的内容对您有用:

MATCH path = (a)-[:b]->(c) 
OPTIONAL MATCH path2 =(c)-[:d]->(e) 
RETURN 
   NODES(path)+COALESCE (NODES(path2),[]), 
   RELATIONSHIPS(path)+COALESCE (RELATIONSHIPS(path2),[])