3
votes

I have built a large database but I came across some wrong connections in Neo4j graph database during testing. I cant simply delete the whole database as the database holds some other data as well. Here trying to explain the scenario through attached image:

My database looks like this

Feat nodes have properties like feat_no and type. Feat nodes are attached to another Feat nodes, Feat nodes are attached to DR nodes then DR is connected to req_id and so on.

I hope image gives the clear picture of the connections.

Question: I just want to delete a particular type of Feat nodes say type "ABC" and all the nodes attached to Feat Node with type "ABC" till the req_id. Means all relationships and nodes should get deleted which are marked inside the blue mark. The network outside the blue mark should not get affected.

Every network gets distinguished based on the type of Feat nodes.

Wants to write Cypher for the same.

1

1 Answers

3
votes

By your description and sample image, I think you can use a variable-length pattern matching to get all reachable nodes from type = "ABC" and then detach delete these nodes:

match (feat:Feat {type : "ABC"})-[*0..]->(node)
detach delete feat
detach delete node