如何使用密码删除两个节点之间的重复关系? [英] how do I delete duplicate relationships between two nodes with cypher?

查看:17
本文介绍了如何使用密码删除两个节点之间的重复关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这个查询时:

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)

这篇关于如何使用密码删除两个节点之间的重复关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆