How to reverse relations on 10 million objects

HI, I need to reverse the relation on 10 million objects what the script should look like using apoc.periodic.iterate

<MATCH (n:Reservation)-[rel:has]->(p:Person) CALL apoc.refactor.invert(rel) yield input, output RETURN input, output/>

Important! I use Neo4j server version: 3.6

image
image

Hi @Slawomir_Jaros !

I do like periodic commit a bit more.

CALL apoc.periodic.commit(
  "MATCH (n:Reservation)-[rel:has]->(p:Person)
   WITH rel limit $limit
   CALL apoc.refactor.invert(rel) yield input, output
   RETURN count(*)",
  {limit:10000});

Tuning on limit according to the max heap on your server.

Lemme know how it goes.

Bennu

Thanks @Bennu

We used below code:


CALL apoc.periodic.iterate(
   "MATCH (n:Reservation)-[rel:has]->(p:Person) return rel",
   "UNWIND $_batch AS item CALL apoc.refactor.invert(item.rel) YIELD input, output RETURN input, output",
   {batchMode: "BATCH_SINGLE", batchSize: 1000}
)
YIELD batches, operations
RETURN batches, operations AS total