How do I use LOAD CSV to update/set properties of existing nodes
One can use LOAD CSV
to perform a bulk update to existing nodes, and create new nodes, as follows.
If we have a .csv called Movies.csv
and its content is:
code,wysiwyg-indent3
code,wysiwyg-indent3
101,The Matrix,463420706
102,The Matrix Reloaded,738576929
103,The Matrix Revolutions,427289109
104,A Few Good Men,24234017
and the current graph includes nodes with a label Movie
for the 1st three movies listed, then the following LOAD CSV
Cypher statement will result in updating the TotalRevenue property for the three existing Movie
nodes and creating a new node for the fourth movie, namely A Few Good Men
:
LOAD CSV FROM "file:///Movies.csv" AS csvLine
MERGE (n:Movie {id:csvLine[0]})
ON CREATE SET n.id=csvLine[0],n.name=csvLine[1], n.TotalRevenue = csvLine[2]
ON MATCH SET n.TotalRevenue = csvLine[2]
Running the above Cypher the first time will result in:
Added 1 label, created 1 node, set 7 properties
Subsequent re-runs of the same LOAD CSV
will result in:
Set 4 properties
Is this page helpful?