What is the behaviour and purpose of the new Cypher operator DETACH DELETE added in Neo4j 2.3.x?
2 Answers
If you want to delete nodes, you need to delete the relationships as well. In previous versions you would need to do:
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n, r
Now you can simply say:
MATCH (n)
DETACH DELETE n
I could not comment on Brian's answer so here it is:
This command:
MATCH n
DETACH DELETE n
Gives to following error:
WARNING: Parentheses are required to identify nodes in patterns, i.e. (n) (line 1, column 7 (offset: 6))
"MATCH n"
^
Thus the correct command is:
MATCH (n)
DETACH DELETE n
detachanddelete:detachremoves the relationships of a node.deletedeletes a node. You will need todetacha node before youdeleteit if it has any relationships.