Deleting data from Neo4j using the Cypher query
In this recipe, we will learn how to delete nodes and relationships from Neo4j. This recipe can be used to delete all nodes/relations or subsets of them.
Getting ready
To step through this recipe, you will need to create some nodes and relationships among them to get the most from this recipe.
How to do it...
We have divided this recipe into the following problem sets:
- Deleting all relationships from the Neo4j graph:
MATCH (n)-[r]-() DELETE r
- Deleting all nodes from the Neo4j graph:
MATCH (n) DELETE n
The preceding query will only work if there are no relationships in the graph.
- Deleting all nodes from the Neo4j graph matching a condition:
MATCH (n) WHERE n.city = "Atlanta" DELETE n # You have to delete all relationships from that node before deleting that node
- Deleting all relationships of a particular type:
MATCH n-[r:ORIGIN]-() DELETE r
- Deleting a property/properties from a particular node/nodes:
MATCH (n) REMOVE n.city # To specify a particular...