cypher删除关系计数大于数字的所有节点关系

时间:2017-10-16 16:37:47

标签: cypher

我的密码出了什么问题。完整描述在标题中。

match (p:P)<-[r:LINK]-(:G) 
with r, count(r) as num 
where num > 100 
delete r

1 个答案:

答案 0 :(得分:1)

在计算r时汇总r,这意味着每一行的计数恰好为1。

要解决此问题,您应汇总p

match (p:P)<-[r:LINK]-(:G) 
with p, count(r) as num 
where num > 100 
match (p)<-[r:LINK]-(:G) 
delete r

另一种选择是collect与列表的关系,unwind与选定的关系:

match (p:P)<-[r:LINK]-(:G) 
with p, count(r) as num, collect(r) as rs
where num > 100 
unwind rs as r
delete r

如果您使用此方法,您也可以省略count(r)并检查rs集合的大小:

match (p:P)<-[r:LINK]-(:G) 
with p, collect(r) as rs
where size(rs) > 100 
unwind rs as r
delete r