To delete single or multiple nodes using Cypher query in neo4j graph database, the DELETE clause can be used.
MATCH (n)
DETACH DELETE n
The above Cypher query will delete all nodes from the graph database. Use the query very carefully because it will delete all nodes along with their properties.
MATCH (n:Person {name: 'John Deo'})
DETACH DELETE n
The Cypher query can be used to delete nodes along with all their relationships with other nodes. We use DETACH DELETE clause to delete node with its relationship to other nodes.
MATCH (n:Movie {name: 'Matrix'})-[r:KNOWS]->()
DELETE r
The above Cypher query will delete the relationships of a node with a Movie label and name property value as Matrix with all other nodes.
0 Comments