cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to bulk delete selected nodes from a list

What would be the best way to delete 1000+ or 100000+ selected nodes? Should I use UNWIND and MATCH to get a list of the nodes I want to delete then detach delete them.

UNWIND $data as delete
MATCH (c:Car)
WHERE c.model = delete.model
DETACH DELETE

This is very slow. Is there a better way?

1 ACCEPTED SOLUTION

Hello @tarendran.vivekanand

You can pass for example ids you want to delete in the data, but if you want to keep your original request, you can still use apoc.periodic.iterate()

CALL apoc.periodic.iterate('MATCH (c:Car) WHERE c.model IN data RETURN c', 'DETACH DELETE c', {batchSize:1000, params:{data:$data}})

Regards,
Cobra

View solution in original post

3 REPLIES 3

Hello @tarendran.vivekanand

You can pass for example ids you want to delete in the data, but if you want to keep your original request, you can still use apoc.periodic.iterate()

CALL apoc.periodic.iterate('MATCH (c:Car) WHERE c.model IN data RETURN c', 'DETACH DELETE c', {batchSize:1000, params:{data:$data}})

Regards,
Cobra

Hello @Cobra
Thanks for the advice but how do you determine the batchSize number of 1000. Is this arbitrary or is there some formula to this?

It depends of the power of your computer , by default I use 1000, but you can try other values between 100 and 10 000