Database Reference
In-Depth Information
Make sure that you replace
<$NEO4J_HOME>
with the actual path or location of
the directory.
4. In Windows, open
<$NEO4J_HOME>\bin\neo4j-shell
and enter the fol-
lowing command; you will see that four nodes, four properties, and four labels are
added:
LOAD CSV WITH HEADERS FROM
"file:\\<$NEO4J_HOME>\\neo4j-import.csv" as csv
CREATE (cinestars:Cinestar {Name : csv.Name, WorkedAs
: split (csv.WorkedAs,",")});
Make sure that you replace
<$NEO4J_HOME>
with the actual path or location of
the Neo4j installation directory..
And you are done!!! Easy isn't it?
Note
LOAD CSV
can import CSV files, which do not contain any headers. Replace the name of
the header with their position in the file within
[]
. For example, the first column of
neo4j-import.csv
will be referred to as csv[1] and the second column would be
csv[2] in the Cypher statement.
In subsequent sections and chapters, all examples will list down the steps for the Unix op-
erating system, unless specified otherwise.
LOAD CSV with MERGE
In the previous example, we have used
CREATE
in
LOAD CSV
, which creates the new re-
cords in the database, but what happens when you have duplicate records in your CSV
file?
That would create duplicate records in your database too, which will be a real problem.
In order to solve the issue with duplicate records, Neo4j provides the
MERGE
command,
which if used will either match the existing nodes and bind them, or create new data and
bind them. It is like a combination of
MATCH
and
CREATE
statements that additionally al-
low you to specify the action that needs to be performed in scenarios where data is
matched or created.