0
votes

I have a requirement to delete ALL nodes and relationships from a parent/root node and NOT delete the parent/root node. The graph Database contains 2 labels (User and Contact) to group the nodes.

Currently I am able accomplish this with the following script, where '6' is the parent/node

MATCH (u:User)-[r]-(c:Contact) 
WHERE u.email = '[email protected]' AND ID(c) > 6 
DELETE c, r

Is there a better way to do this?
Is there a way to tell Neo4J not to delete the parent/root node?

2
Did you mean ID(c) <> 6?jjaderberg

2 Answers

0
votes

That's a good way, what is your issue with it?

You told Neo4j not to delete the User node.

0
votes

The issue is that I have to know the node id. I was hoping to just match a property on the parent node to identify it vs. node id.

Something like this:

MATCH (u:User)-[r]-(c:Contact) WHERE u.email = '[email protected]' AND NOT u.mail = '[email protected]' DELETE c, r

Which does not seem to work, any suggestions ?