Neo4j Cypher: copy relationships and delete node

后端 未结 2 1430
有刺的猬
有刺的猬 2021-01-23 23:45

I\'m trying to copy all inward relationships of a node (n) to another node (m) (both of witch I know the ids) before deleting (n), but I c

2条回答
  •  我在风中等你
    2021-01-23 23:56

    assuming all incoming relationships are of same type say 'foo'. Then you could do the shorter following query:

    START n=node(id1),m=node(id2) 
    MATCH n<-[r:foo]-(p) 
    WITH collect(p) as endNodes,m
    FOREACH(mm in endNodes | CREATE m-[:foo]->mm)
    

    Which avoids the double foreach

提交回复
热议问题