Assume I have this model in neo4j:
(n2) -> (n3)-> (n9)
/\
|
(n4)<-(n1)->(n5)->(n6)
| |
\/ \/
(n7) (n8)
I need a cypher to change relationship between (n1) and (n2) to (n1) and (n6), like this:
(n2) -> (n3)-> (n9)
/\
|
(n4)<-(n1)->(n5)->(n6)
| |
\/ \/
(n7) (n8)
To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.
You can change the nodes associated with a label but you can't change the type of a relationship.
You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.
Neo4j cannot store bidirectional relationships. No way around this, you can however treat relationships as bidirectional when querying your graph.
For those without APOC, Here is how to copy the relationship
MATCH (n1)-[r1:foo]->(n2),(n6)
WHERE n1.id = 1 AND n2.id = 2 and n6.id = 6
CREATE (n2)-[r2:foo]->(n6)
SET r2=r1
DELETE r1
If you have APOC Procedures installed, you can use a graph refactoring procedure to change the end point of a relationship. You'll need a match query to get the relationship, and the new start node, then use:
call apoc.refactor.from(rel, newStartNode)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With