Neo4j - Node Labels

Labels are the 'TABLES' of the Graph database world.

Here's some useful methods of manipulating Labels.

Rather than delete and create your Nodes in Neo4j just to change the label, it may be easier to try one of the two methods below:

Rename node - Method 1:
MATCH (s:OldLabel)
SET s:NewLabel
REMOVE s:OldLabel


Rename node - Method 2:
MATCH (n:OldLabel)
WITH COLLECT(n) AS nodes
CALL apoc.refactor.rename.label('OldLabel','NewLabel'[,nodes])
YIELD errorMessages AS eMessages
RETURN eMessages;

Do you have any more ways of 'renaming' Nodes in Neo4j?

Nodes can also have more than one Label.

Here is how to add and remove a Label on a Node where the only matching property is {name : 'Greg'}

How to add a new label
MATCH (n { name: 'Greg' })
SET n:NewLabel
RETURN n.name, labels(n) AS labels

How to remove a label
MATCH (n { name: 'Greg' })
REMOVE n:OldLabel
RETURN n.name, labels(n) AS labels



Comments

Popular posts from this blog

Property DataType - apoc.meta.type

Stopping and Starting the Neo4j Database

NULLS in Neo4j