O'Reilly logo

Learning Neo4j 3.x - Second Edition by Rik Van Bruggen, Jérôme Baton

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

Delete data

The first rule when deleting a node is that it is not connected to other nodes anymore. Just like the other operations, it is a matter of matching before deleting a node.

Should we want to DELETE Mr. Montague, the query would be as follows:

MATCH (r:Person{lastName:"Montague"})DELETE r;

However, this will fail with an error because of the LOVES relation.

So we either delete the relation first, or we use DETACH DELETE:

MATCH (r:Person{lastName:"Montague"}DETACH DELETE r;

Now, Juliet is alone.

We have now covered a solid base of Cypher. We will see more throughout the next chapters, while the next paragraph will be useful as a reference to this basis.

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