Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-17-2018 05:37 AM
Hello everyone !
I'm trying to move every relationships of a node to an another.
Here is my query for now :
MATCH(n:Resource {name: 'source-resource'})-[r]-() with collect(distinct r) as relations,n
MATCH(n2:Resource {name: 'destination-resource'}) with n,n2,relations
CALL apoc.create.relationship(n, type(relations), NULL, n2) YIELD rel
return rel
Of course that doesn't work since apoc.create.relationship awaits a relationship argument instead of a List
Thanks in advance for your answers
Solved! Go to Solution.
09-18-2018 01:11 AM
Thank you very much Michael !
As I wanted every relationships (from and to) I also used apoc.refactor.from and ended up with that :
MATCH(n2:Resource {name: 'destionation-resource'})
MATCH(n:Resource {name:'source-resource'})<-[r]-()
OPTIONAL MATCH(n)-[r2]->()
CALL apoc.refactor.to(r, n2) YIELD input, output
CALL apoc.refactor.from(r2, n2) YIELD input AS i, output AS o
RETURN *
And it worked perfectly !
Thank you Michael. I took a look at your medium blog, great content I will read some of them
Have a good day !
09-17-2018 04:32 PM
You also forgot to pass your n
with the WITH
There is a dedicated procedure to move relationships to a new target,
apoc.refactor.to
this should work
MATCH(n2:Resource {name: 'destination-resource'})
MATCH (n:Resource {name: 'source-resource'})-[r]-()
CALL apoc.refactor.to(r, n2) YIELD rel
RETURN rel
see: https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_refactoring_2
09-18-2018 01:11 AM
Thank you very much Michael !
As I wanted every relationships (from and to) I also used apoc.refactor.from and ended up with that :
MATCH(n2:Resource {name: 'destionation-resource'})
MATCH(n:Resource {name:'source-resource'})<-[r]-()
OPTIONAL MATCH(n)-[r2]->()
CALL apoc.refactor.to(r, n2) YIELD input, output
CALL apoc.refactor.from(r2, n2) YIELD input AS i, output AS o
RETURN *
And it worked perfectly !
Thank you Michael. I took a look at your medium blog, great content I will read some of them
Have a good day !
All the sessions of the conference are now available online