I have a tree structure, like node(8) has two children node(13) and node(14). How can I delete all children when I delete node(8) by cyhper.
I write cypher like this:" START r=node(8) MATCH r-[:children*0..]-> d With d Match d-[x]-() Delete d,x"
It should work, but actually it only delete node(8) and get some error. I find that actually it's trying to delete a collection like this.
- ---d-------------------r
- Node(8)----------Rel(16)
- Node(8)----------Rel(17)
- Node(9)----------Rel(16)
- Node(10)---------Rel(17)
And after cyhper delete first Node(8), it try to delete Node(8) for second time and get error because it doesn't exist anymore.
It's wired cause when I write cypher like this: "START r=node(8) MATCH r-[:children*0..]-> d Return d" It returns:
- ---d---
- Node(8)
- Node(8)
- Node(9)
- Node(10)
And it's right. But as we know, I can't delete them with relationship on them, so I need to write a cypher with "WITH":
"START r=node(8) MATCH r-[:children*0..]-> d With d Match d-[x]-() Return d,x"
And it get the wrong result again.
- ---d-------------------r
- Node(8)----------Rel(16)
- Node(8)----------Rel(17)
- Node(9)----------Rel(16)
- Node(10)---------Rel(17)
Can anyone help me? It's really depressed. I really like neo4j, but I find the "Delete" part is such tough. Why not just use "Force Delete" and make Neo4j to auto delete relationships just like this:
"START r=node(8) MATCH r-[:children*0..]-> d FORCE DELETE d"
And btw, why can't use distinct in "Delete" part?