O'Reilly logo

Neo4j Cookbook by Ankur Goel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required