cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Exercise 16.3 - Importing data from CSV

bluabaleno
Node Clone

Answer given by the tutorial.
LOAD CSV WITH HEADERS
FROM 'http://data.neo4j.com/v4.0-intro-neo4j/actors.csv'
AS line
MERGE (actor:Person {name: line.name})
ON CREATE SET actor.born = toInteger(trim(line.birthYear)), actor.actorId = line.id
ON MATCH SET actor.actorId = line.id

My answer:
LOAD CSV WITH HEADERS
FROM 'http://data.neo4j.com/v4.0-intro-neo4j/actors.csv'
AS line
MERGE (p:Person{actorId:toInteger((line.id)})
ON CREATE SET
p.name = line.name,
p.born = toInteger(trim(line.birthYear))

Why is this part needed?
actor.actorId = line.id
ON MATCH SET actor.actorId = line.id

Why do a second MATCH SET for actorId?

1 ACCEPTED SOLUTION

This is a side-effect of how "clean" the data is that you are importing.

The data may have repeated actor lines. If a duplicate is found that means that that actor has already been loaded and we will use the latest id encountered in the CSV file.

Elaine

View solution in original post

1 REPLY 1

This is a side-effect of how "clean" the data is that you are importing.

The data may have repeated actor lines. If a duplicate is found that means that that actor has already been loaded and we will use the latest id encountered in the CSV file.

Elaine