【问题标题】:How to remove relations while iteration with UNWIND using cypher如何在使用 cypher 使用 UNWIND 进行迭代时删除关系
【发布时间】:2016-06-08 06:30:58
【问题描述】:

然后以下查询获取特定用户的所有组 展开每个结果(每个组),并且仅当与该组的计数关系为 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 

谢谢。

【问题讨论】:

    标签: neo4j cypher neo4jclient


    【解决方案1】:

    您可以在WHERE 中使用size,例如:

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

    您不需要迭代,默认情况下,MATCH 之后的后续子句将针对 MATCH 中找到的每一行执行,因此假设第一个 MATCH 返回以下内容:

    me     rel     allGroups
    1      rel3     node5
    1      rel4     node6
    

    然后DELETE 将在第一行执行,然后在第二行执行,依此类推……

    【讨论】:

    • 但是你如何在每个组上迭代这种方式?因为您将获得组列表,如果传入关系的数量为 1,则需要检查每个组,将其删除,否则保留它
    • 不需要迭代,只需在WHERE子句中给模式添加方向即可
    • 大小如何在 allGroups 中的每个组上实际迭代?
    • 我加了一点解释
    • 发现新东西很酷,否则我们会很无聊:)
    猜你喜欢
    • 2022-10-19
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    • 2014-11-10
    • 2013-10-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    相关资源
    最近更新 更多