如何在使用Cypher的UNWIND迭代时删除关联

3
以下查询获取特定用户的所有组,然后对每个结果(每个组)进行展开,并且仅当该组的关系计数为1时才应删除所有传入关系。
example: group1<-user1  (will delete the incoming relationship to the group)

         group1-<user1 
         group1-<user2 (will remain all incoming relationships to the group)

可以帮忙完成吗?
MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP)
unwind userGroups as group  
 //how to use CASE or WHERE in order to check if this group 
has only 1 relationship just remove it 

谢谢。
1个回答

3
您可以在WHERE语句中使用size,例如:
MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP)
WHERE size((allGroups)<-[:relation_group]-()) = 1
DELETE rel

您不需要迭代,因为默认情况下,在MATCH找到的每一行后面的子句都会被执行,因此假设第一个MATCH返回以下内容:

me     rel     allGroups
1      rel3     node5
1      rel4     node6

然后会逐行执行DELETE,首先删除第一行,然后是第二行,以此类推...


你不需要迭代,只需在WHERE子句中将方向添加到模式中。 - Christophe Willemsen
从allGroups中,实际上每个组的大小是如何迭代的? - rayman
我建议您参加一些在线的Cypher课程、教程或Graphgists,以更好地了解Cypher ;-) - Christophe Willemsen
你说得对。我会尽力涵盖所有内容。只要我发现新的概念,就会更新。 - rayman
1
发现新东西很酷,否则我们会感到无聊 :) - Christophe Willemsen
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接