Neo4j 如何在使用cypher展开迭代时删除关系

Neo4j 如何在使用cypher展开迭代时删除关系,neo4j,cypher,neo4jclient,Neo4j,Cypher,Neo4jclient,下面的查询将获取特定用户的所有组 对每个结果(每个组)展开,并且仅当与该组的计数关系为1时,才应删除所有传入关系 example: group1<-user1 (will delete the incoming relationship to the group) group1-<user1 group1-<user2 (will remain all incoming relationships to the group) 谢谢。您

下面的查询将获取特定用户的所有组 对每个结果(每个组)展开,并且仅当与该组的计数关系为1时,才应删除所有传入关系

example: group1<-user1  (will delete the incoming relationship to the group)

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

谢谢。

您可以在
的WHERE
中使用
大小,例如:

MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP)
WHERE size((allGroups)<-[:relation_group]-()) = 1
DELETE rel

然后将对第一行执行
DELETE
,然后对第二行执行,等等。

但是如何在每个组上以这种方式迭代?因为你会得到一个组列表,需要检查每个组,如果传入关系的数量是1,则删除它,否则保留它。你不需要迭代,只需在WHERE子句中的模式中添加方向。从allGroups中,每个组的大小实际上是如何迭代的?我添加了一些解释,发现新东西很酷,否则我们会感到无聊:)
MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP)
WHERE size((allGroups)<-[:relation_group]-()) = 1
DELETE rel
me     rel     allGroups
1      rel3     node5
1      rel4     node6