Exercise 16.3 - Importing data from CSV

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?

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

1 Like