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 return number of deleted nodes when using apoc.periodic.iterate?

Hi all,

I realize when deleting nodes, there is no information returned like number of deleted nodes or even number of delete relationships.
Example query

CALL apoc.periodic.iterate('MATCH (u:User) 
WHERE u.name IN $data
OPTIONAL MATCH (u)-[:OWNS]->(c:Car) 
RETURN u, c', 
'DETACH DELETE u, c', {batchSize:1000, params:{data:$data}})

In the above example, I want to return the number of user nodes deleted and number of car nodes deleted if it is possible with the additional info I get from using apoc.periodic.iterate
Thanks in advance.

1 ACCEPTED SOLUTION

Hello @tarendran.vivekanand

One solution is to count nodes before and count after and compute the difference

Regards,
Cobra

View solution in original post

4 REPLIES 4

You can YIELD the total value from the procedure call to get the total number of rows:

CALL apoc.periodic.iterate('MATCH (u:User) 
WHERE u.name IN $data
OPTIONAL MATCH (u)-[:OWNS]->(c:Car) 
RETURN u, c', 
'DETACH DELETE u, c', {batchSize:1000, params:{data:$data}})
YIELD total
RETURN total

You can yield any of the values below:

(batches :: INTEGER?, total :: INTEGER?, timeTaken :: INTEGER?, committedOperations :: INTEGER?, failedOperations :: INTEGER?, failedBatches :: INTEGER?, retries :: INTEGER?, errorMessages :: MAP?, batch :: MAP?, operations :: MAP?, wasTerminated :: BOOLEAN?, failedParams :: MAP?)

Hello @adam.cowley

Thanks for the reply

Based on your reply,
It only returns the total rows but doesn't return the total number of nodes deleted. In the query I have also match the user to car this is a one-to-many relationship thus I can be deleting a lot more nodes then rows. I would also like to know if possible the number of nodes deleted for each (i.e. number of nodes deleted for user and number of nodes deleted for cars).

Hello @tarendran.vivekanand

One solution is to count nodes before and count after and compute the difference

Regards,
Cobra

Hello @Cobra
Thank you. More work though

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online