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.

Deleting n records results in n + 1 queries

I can't figure out how to use neo4j-ogm to generate a (single) query that will delete n records.
I'd like to write some OGM code that achieves something like this:

MATCH (n: Artist) WITH n SKIP 0 LIMIT 100 DELETE n

But my code (below) generates one of these queries:

MATCH (n:`Artist`) WITH n SKIP 0 LIMIT 100 RETURN n - {}

Followed by 100 queries like this:

MATCH (n) WHERE ID(n) = $id OPTIONAL MATCH (n)-[r0]-() DELETE r0, n - {id: 15992}
MATCH (n) WHERE ID(n) = $id OPTIONAL MATCH (n)-[r0]-() DELETE r0, n - {id: 15993}
...

Here is my ogm code:

Pagination pagination = new Pagination(0, 100);
Session session = getSession.get();
Collection<Artist> records = session.loadAll(Artist.class, pagination, DEPTH_LIST);
session.delete(records);

Any help is appreciated, thank you!

1 REPLY 1

Could you please drop an issue at Issues · neo4j/neo4j-ogm · GitHub ? This would also help you to keep track of the updates.
Neo4j-OGM creates a single delete statement for every object in the collection. This is due to the fact that otherwise an optimistic locking check can not get defined, respectively Neo4j-OGM cannot tell exactly where the check failed if one occurs.
But for sure we can have a deeper lock on this, if this is a real issue for your use-case.