Taja Jan
Taja Jan

Reputation: 1411

Deleting a node and its relationships in a graph database using Cypher

I need to delete a node and all its relationships in a graph database using Cypher. Can you provide an example of how to do this, and is it possible to undo or roll back these changes if needed?

Upvotes: 0

Views: 285

Answers (1)

amanb
amanb

Reputation: 5473

To delete a node and its relationships using Cypher, use the DETACH DELETE command. For example, to delete all Movie nodes where movie names start with the word "The" and all relationships for such nodes, we can write the query below:

MATCH (m:Movie)
WHERE m.name STARTS WITH 'The'
DETACH DELETE m;

The DELETE command will delete the nodes and DETACH command will delete all relationships for the nodes.

Upvotes: 1

Related Questions