Reputation: 4319
I want to delete all the relationships and nodes when deleting a particular node
For example
I have a structure like
A->B->C->D->D1->E1
->D2
->D3
What I want is when I delete node B, all the relations and nodes which are directly or indirectly connected to this node B gets deleted like if I delete B then C, D D1, D2, D3, E1 should get deleted as well as their relations.
Is there a way to do that? I have a graph wherein a state node has a lot of store nodes and each store nodes have a lot of items nodes and each item nodes have a lot of price nodes.
Now if I delete State node, all the store which are connected to it should get deleted, and all the items which are connected to these stores should get deleted and then the price nodes which are connected to these items nodes should bet deleted
Upvotes: 0
Views: 103
Reputation: 67044
The following Cypher query will remove an entire subgraph rooted at a specific node.
I pretend that you find the root of the subgraph by testing that its xxx
property has the value 'yyy'
.
MATCH (root {xxx:'yyy'})-[r1*]->(x)
OPTIONAL MATCH ()-[r2]->(root)
FOREACH(r IN r1 | DELETE r)
DELETE r2, root, x;
Upvotes: 2