Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-12-2021 10:37 AM
Apologies if this is a simple/newbie question - I've looked everywhere and cannot find an answer.
I would like to duplicate all the relationships that one node has, to another.
So for example, using the classic movie graph:
(mail:Movie{name:"You've Got Mail"})<-[:ActedIn{year:1998})]-(tom:Actor{name:"Tom Hanks"})<-[:Directed]-(nora:Director{name:"Nora Ephron"})
I'd like to be able to duplicate those relationships so that (meg:Actor{name:"Meg Ryan"}) is also connected to nora and mail with exact copies of those relationships - types and properties included.
Considerations:
I figure there is some combination of FOREACH and apoc's create.relationship() procedure but i cannot figure it out!
Any help gratefully received. this can't be something that's never come up before!
Thanks
11-14-2021 09:43 AM
Yes you're right.
Easiest via 2 runs one per direction
MATCH (c:Actor {name:"Meg Ryan"})
MATCH (a:Movie)-[rel]->(b:Actor {name:"Tom Hanks"})
call apoc.create.relationship(a,type(rel),properties(rel), c) yield relationship
return count(*)
For other nodes like the director, just extend the pattern and add a second create call.
But watch out for cardinalities so that you don't accidentally create multiple rels of the same type.
All the sessions of the conference are now available online