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?

Hello @tarendran.vivekanand :slight_smile:

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() :slight_smile:

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

Regards,
Cobra

1 Like

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

1 Like

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

1 Like