cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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?

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