Reputation: 1441
Is it possible to change a label on a node using Cypher?
I have a node with label Book
, as shown below. I want to change the Book
label to DeletedBook
.
(u:Person)-[r]-(b:Book{id:id1})
(u:Person)-[r]-(b:DeletedBook{id:id1})
Upvotes: 10
Views: 7126
Reputation: 483
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)
Upvotes: 1
Reputation:
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.
Upvotes: 17