How to change/update a label in Neo4j - Cypher?

You can use 'REMOVE' for removing and SET for adding new label.

eg:

MATCH (p:Person)-[r]-(b:Book {id: id1})
REMOVE b:Book
SET b:DeletedBook
RETURN b

Best practice is to add a 'delete' label to the node we want to delete. Don't remove the label of a node when we update.

MATCH (p:Person)-[r]-(b:Book {id: id1})
SET b: Deleted
RETURN b

so book node will have 2 labels (:Book:Deleted)


You can do that using REMOVE on the Book label and SET on the new label:

MATCH (p:Person)-[r]-(b:Book {id: id1})
REMOVE b:Book
SET b:DeletedBook
RETURN b

You should check out the Neo4j Cypher Refcard for a complete reference to Cypher 2.x.

Tags:

Neo4J

Cypher