Neo4j removes all nodes with specified label and their relationship in one request

I am decoupling my Neo4j database from isolated sub-batteries using labels. During development, I often need to clear the entire database. I am currently doing this with:

MATCH (n:myLabel)-[r]-() DELETE n, r
MATCH (n:myLabel) DELETE n

      

I need two queries because I have to delete all relationships, at the same time with their nodes, but I don't know how to match unrelated nodes at the same time. Is there a way to destroy the entire subgraph marked with a label in one request? I'm on Neo4j 2.2.1

+3


source to share


1 answer


Here you go:



MATCH (n:myLabel) OPTIONAL MATCH n-[r]-() DELETE n, r

      

+4


source







All Articles