'Neo4j Delete All Nodes and Relationships
I want to delete all nodes and relationships.
I run MATCH ()-[r]-() DELETE r to delete all the relationships.
Then, I run MATCH (n) DELETE n to delete all the nodes. It does delete all the nodes, but the problem is that it also gives me this error:
Neo.DatabaseError.Transaction.TransactionCommitFailed
Unable to complete transaction.
How do I delete all nodes and relationships with getting this error?
Solution 1:[1]
To delete all nodes and all relationships, I do DETACH DELETE
MATCH (n)
DETACH DELETE n;
If nothing works, then rename (or remove) your neo4j data folder and restart your server.
<HOME_NEO4j>/data/data/transactions/neo4j
Solution 2:[2]
It looks like your database is hitting an OOM Exception.
As stated in Large Delete Transaction Best Practices in Neo4j
If you need to delete some large number of objects from the graph, one needs to be mindful of the not building up such a large single transaction such that a Java OUT OF HEAP Error will be encountered.
Delete all constraints and indexes
CALL apoc.schema.assert({},{},true);
Batch delete with CALL {} IN TRANSACTIONS syntax or apoc.periodic.iterate:
MATCH (n:Foo) where n.foo='bar' CALL { WITH n DETACH DELETE n } IN TRANSACTIONS OF 10000 ROWS;
OR
CALL apoc.periodic.iterate(
"MATCH (n) RETURN n",
"DETACH DELETE n",
{batchSize:10000, parallel:false})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Thennan |
