Neo4J apoc.create.vRelationship 独特的关系

Neo4J apoc.create.vRelationship unique relationsip

几个月前我问过 ,答案很完美。

MATCH (p:part)<-[:SUPPLIES]-(:supplier)-[:LOCATED_IN]->(c:country)
RETURN p, c, apoc.create.vRelationship(p, 'IS_IN', {}, c) as rel

我在上述解决方案中遇到的问题是我现在有两个节点,它们之间有很多完全相同的关系类型。有没有办法 return 基于类型的不同关系?

您可以使用WITH DISTINCT p, c过滤掉重复的pc对,这样每对之间就只有一个虚拟关系:

MATCH (p:part)<-[:SUPPLIES]-(:supplier)-[:LOCATED_IN]->(c:country)
WITH DISTINCT p, c
RETURN p, c, apoc.create.vRelationship(p, 'IS_IN', {}, c) as rel