如何删除节点和所有相关节点不仅关系 - neo4j cypher 1.8

时间:2012-11-26 16:29:12

标签: java spring java-ee neo4j

如何删除节点和所有相关节点不仅关系 例如

account-[:GGroup]-group,
group-[:GEvent]-event,
group-[:GMember]-member,
group-[:GAlbum]-album,
album-[:GPhoto]-photo,

所以我想删除所有相关节点的组(事件和专辑(和照片)),这是我的工作......我正在使用java。

    START group = node:GGroup('dbId:1') 
    MATCH group-[gp:privacy]-gPrivacy,
            group-[gm:GroupMember]-(),
            group-[ge:GroupEvent]-event,
            event-[ep:privacy]-gePrivacy,
            event-[eep:EventParticipant]-(),
            event-[ea:EventAlbum]-eventAlbum,
            eventAlbum-[ap:privacy]-geaPrivacy,
            eventAlbum-[aph:AlbumPhoto]-eventAlbumPhoto,
            eventAlbumPhoto-[ept:PhotoTag]-eventAlbumPhotoTag,
            event-[ev:EventVideo]-eventVideo,
            eventVideo-[vp:privacy]-gevPrivacy,
            group-[ga:GroupAlbum]-groupAlbum,
            groupAlbum-[gap:privacy]-gaPrivacy,
            groupAlbum-[aphoto:AlbumPhoto]-groupAlbumPhoto,
            groupAlbumPhoto-[gpt:PhotoTag]-groupAlbumPhotoTag,
            group-[gf:GroupFile]-groupFile 
            delete group,gm,ge,event,ep,gePrivacy,eep,ea,eventAlbum,ap,geaPrivacy
            ,aph,eventAlbumPhoto,ept,eventAlbumPhotoTag,ev,eventVideo,vp,gevPrivacy,ga,
            groupAlbum,gap,gaPrivacy,aphoto,groupAlbumPhoto,gpt,groupAlbumPhotoTag,gf,
            groupFile,gp

2 个答案:

答案 0 :(得分:1)

START g=node({id_of_group_node})
MATCH acc-[ag:GGroup]-g
     ,g-[ge:GEvent]-e
     ,g-[gm:GMember]-m
     ,g-[ga:GAlbum]-a
     ,a-[ap:GPhoto]-p
DELETE g, ge, e, gm, m, ga, a, ap, p, ag

答案 1 :(得分:0)

如果要删除所有相关节点,则无需在MATCH阶段逐个显式匹配它们。你可以简单地找到除开始之外的所有照片(+专辑照片):

START account=node(...)
MATCH account-[:GGroup]-group,
      group-[r1]-all,
      group-[:GAlbum]-()-[r2]-photo
WHERE Id(all)<>Id(account)
DELETE group, r1, all, r2, photo.