fwind
fwind

Reputation: 1314

How to delete lots of nodes

I want to delete all nodes of a given type and their relations. In total there are 1.4 million nodes of this type.

Using MATCH (n:Type) DETACH DELETE n Neo4j hangs itself up after a few minutes and has to be restarted.

Is there a better way to delete a large number of nodes? Can I delete them in chunks somehow (LIMIT is not supported with DELETE)?

Upvotes: 1

Views: 322

Answers (1)

Evgen
Evgen

Reputation: 1338

Try this

Match (n:Type) with n
Match (n)-[r]-()
Delete n, r

If you want to delete them in chunks the query would look like

Match (n:Type) with n limit 1000
Match (n)-[r]-()
Delete n, r

Upvotes: 1

Related Questions