Skip to content
Related Articles
Open in App
Not now

Related Articles

Neo4j Delete Node

Improve Article
Save Article
  • Last Updated : 06 Oct, 2022
Improve Article
Save Article

In Neo4j to delete a node or relations between nodes you have to use DELETE clause. To delete any node you need DELETE clause with the MATCH statement, the MATCH statement data will find the specific node and whichever node is matched with the statement that node will be vanished. Similar to the CREATE and RETURN statement just it will replace the CREATE with MATCH and RETURN with the DELETE. Below examples will illustrate the approach. Example: The basic way to delete a node is to find the node and delete the match node, but before you can check the node is that the node you want to delete by using RETURN statement after that you can fire below query. This query will delete the node where label is “GeeksforGeeks” Tag is “A Computer Science Portal” and the type is “Edutech”.

  • To delete node:
$ MATCH (a:GeeksforGeeks { Tag : "A Computer Science Portal", Type : "Edutech" }) 
  • Output:

Deleting multiple nodes: To delete multiple nodes use the DELETE statement and separate the nodes by “, ” coma or you can use multiple time MATCH statement Like the below query.

  • Multiple nodes deleted: 
$ DELETE (a:GeeksforGeeks { Tag: "A Computer Science Portal"}), 
(b:W3School { Tag: "We are the Learner"}) 
MATCH a, b
  • or
$ MATCH (a:GeeksforGeeks { Tag: "A Computer Science Portal"}) 
MATCH (b:W3School { Tag: "We are the Learner"}) 
  • Output:

Delete all nodes: To delete all the nodes at once is to much short query to fire the below query will delete all the nodes at once.

  • Delete all nodes:
  • Output:

Note: To delete any node or nodes that containing relationship with other nodes will display an error message.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!