cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

deleting a subgraph

verachkaverachk
Graph Buddy

Hello , can you help me with a query that would be able to delete a specific graph (by it's id or name)

 

verachkaverachk_1-1654780670841.png

my mission is to delete all the nodes and their realtions from my root that is the green "MyGraph" but only them, I do not want to delete all the other nodes that we do not see in the image and their relations in my db 

 

1 ACCEPTED SOLUTION

Is this is self-contained subgraph, i.e. it does not connect to other nodes you want to keep? If so, you can try this. I used it on the shown subgraph, and it worked fine. Change the match clause predicate to match on your 'black' node. It relies on the APOC library, so you will need to install it if you have not done so already.

MATCH (p) where id(p) = 100
CALL apoc.path.subgraphNodes(p, {})
YIELD node
detach delete node

 Screen Shot 2022-06-16 at 7.44.04 PM.png

View solution in original post

4 REPLIES 4

I'm not sure i understand the question. If you have the `<id>`  of your node, by clicking it by clicking it and seeing the `Node properties` box, you could do this query to delete node and relationships: 

```  MATCH (n) WHERE id(n) = <MYID> DETACH DELETE n ```

Is this what you need?

Hello  i have entered to <MYID> the relavent id, that from it I wanted to delete all the connected nodes but it didn't work. What did I do wrong? and what I meant was that i try to pick the node I have marked in black and with it's id to delete the whole yellow "graph" that starts from him

verachkaverachk_1-1655410823742.png

 

 

 

Is this is self-contained subgraph, i.e. it does not connect to other nodes you want to keep? If so, you can try this. I used it on the shown subgraph, and it worked fine. Change the match clause predicate to match on your 'black' node. It relies on the APOC library, so you will need to install it if you have not done so already.

MATCH (p) where id(p) = 100
CALL apoc.path.subgraphNodes(p, {})
YIELD node
detach delete node

 Screen Shot 2022-06-16 at 7.44.04 PM.png

It worked 🙂 

thank you so much!!