Ljubica Lazarevic
1 min readMay 8, 2019

--

Quick loading of node properties during CSV import

Recently I found out about a rather neat way of loading all of the fields. If you want to have all of the fields in a CSV for one node label, you can do this in one go, rather than individually setting each property.

Let’s say we have the following headers personInfo.csv:

id, name, email, dob 

As it turns out, we want all of these properties in our Person node. Assuming we’ve created an index on id:

CREATE INDEX ON :Person(id)

We could run the following to load the data from the file:

LOAD CSV WITH HEADERS FROM ‘file:///personInfo.csv’ AS line
MERGE (p:Person {id:line.id})
ON CREATE SET p.name = line.name, p.email = line.email, p.dob = line.dob

But, much more succinctly, we can do this:

LOAD CSV WITH HEADERS FROM ‘file:///personInfo.csv’ AS line
MERGE (p:Person {id:line.id})
ON CREATE SET p += line

--

--

Ljubica Lazarevic
Ljubica Lazarevic

Written by Ljubica Lazarevic

Technologist — data geek — solver of problems

No responses yet