Search code examples
neo4jcypherneo4j-apoc

How to rename (remove old and add new) property for all nodes in Neo4j database?


I have a db of almost 50000 nodes and almost 300k properties.

I was able to rename node lables like below:

// Rename x Node labels
MATCH (n:OLD_LABEL {id:14})
REMOVE n:OLD_LABEL
SET n:NEW_LABEL

MATCH (n:CLASSIFICATIONSTANDARD)
REMOVE n:CLASSIFICATIONSTANDARD
SET n:Eclass;

But when I try to change the name of a property for all nodes the neo4j crashed. Can I run this script in a batch of 1000 each?

CALL apoc.periodic.iterate https://neo4j.com/labs/apoc/4.4/overview/apoc.periodic/apoc.periodic.iterate/

Looks like a good options, but it only allows three argument so I dont know how to run all this code:

match (t:Eclass) 
SET t.irdicc = t.irdiCc 
REMOVE t.irdiCc
return true;

match (t:Eclass) return t.irdicc;

Solution

  • You can use subqueries in transactions for that https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-call-in-transactions

    The :auto is needed if you plan to run this in the Neo4j browser

    :auto MATCH (t:Eclass)
    CALL {
      WITH t
      SET t.irdicc = t.irdiCc 
      REMOVE t.irdiCc
    } IN TRANSACTIONS OF 100 ROWS