Neo4j - Managing Relationship names

In a Graph Database Relationships between the nodes are considered to be as important, if not more important than the nodes themselves.

A Relationship joins two nodes or 'loops-back' to the same node.

The relationship can be created or deleted but cannot be renamed.

How to delete relationship
MATCH (n { name: 'Greg' })-[r:KNOWS]->()
DELETE r

To rename a Relationship you do a simultaneous create and delete. Create a new relationship and delete the old as below:

Rename relationship
MATCH (n)-[rel:IS_CONNECTED_TO]->(m)
MERGE (n)-[:KNOWS]->(m)
DELETE rel

MATCH (n)-[rel:IS_CONNECTED_TO]->(m) WITH rel
CALL apoc.refactor.setType(rel, 'KNOWS') YIELD input, output RETURN *

Comments

Popular posts from this blog

Property DataType - apoc.meta.type

Stopping and Starting the Neo4j Database

NULLS in Neo4j