I want to delete the the special "root" node in my Neo4j Database.
I already found some Question/Answer in SO, but they are not useful, from different reason.
We uses a db:DATABASE node for store the tenant data in Neo4j, and all other node is somehow connected to this node. So the real Neo4j Root Node just have connections to this DATABASE-s. It means whet a new node is created under the tenant, this new node intermediately has a connection to DATABASE node, and the connection name is CONTAINS.
here is the creation code of the DATABASE node
CREATE (db:Database { Name: 'TenantName' } ) " )
And I want to delete the whole Tenant, it means I want to delete the whole DATABASE, and all the node which is connected to DATABASE node.
If delete the node with this simple cypher, the node is deleted, but all connected node is still remain in database.
MATCH (db:Database)
WHERE db.Name = 'TeanantName'
DETACH DELETE db
The challenge is: We don't know any Node name or any connection under the DATABASE node.
Already Answered SO questions:
- How to delete a node and its connected nodes with Neo4j cypher query? In this answer, we know the name of the relationship. "ACTED_IN", and assumes we have only this connection to deleted node.
- Neo4j: How to delete all nodes and relationships beyond a node? In this case, we know the real node structure, but in our case we don't know.
- cypher delete node and all the list of related node This assumes that each node in the path is no longer anchored to anything other than the nodes in the path otherwise they will not be able to be removed. Which is not true in our case.
- Neo4j how to delete nodes recursively from some start node In this case the whole graph structure is known.
Thank you guys!