如何删除使用密码的两个节点之间的重复关系?
问题描述:
当我运行此查询时:
START n1=node(7727), n2=node(7730)
MATCH n1-[r:SKILL]->n2 RETURN r
它给了我两个节点之间重复关系的列表.我要在密码查询中添加些什么来遍历该关系以保持一种关系并删除其余的关系?
it gives me a list of duplicate relationships that I have between the two nodes. what do I add to the cypher query to iterate over the relationship to keep one relationship and delete the rest?
答
要针对两个已知节点执行此操作:
To do this for two known nodes:
start n=node(1), m=node(2) match (n)-[r]->(m)
with n,m,type(r) as t, tail(collect(r)) as coll
foreach(x in coll | delete x)
要针对所有关系全局进行此操作(请注意,根据图形的大小,此操作可能会非常昂贵):
To do this globally for all relationships (be warned this operation might be very expensive depending on the size of your graph):
start r=relationship(*)
match (s)-[r]->(e)
with s,e,type(r) as typ, tail(collect(r)) as coll
foreach(x in coll | delete x)