Neo4j: Get all nodes in a graph, even those that are unconnected by relationships

So, this gives you all nodes:

MATCH (n)
RETURN n;

If you want to delete everything from a graph, you can do something like this:

MATCH (n)
OPTIONAL MATCH (n)-[r]-() 
DELETE n, r;

Updated for 2.0+

Edit:
Now in 2.3 they have DETACH DELETE, so you can do something like:

MATCH (n)
DETACH DELETE n;

Leave a Comment