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.

CSV Import Multiple Values

Hi everyone, I have a trouble here when doing LOAD CSV .

My csv file format : Garage.csv
VehicleID is created based on Vehicle.csv
The idea here to create (v:Vehicle)-[:REPAIRED_IN]->(g:Garage)
garageID, garageName, vehicleID
1, XZ Garage, [20,21,22]

How do I import and create a relationship for it. As a garage might have more than one vehicle that came to repair.
Is it something to do with FOREACH ?
Thank you in advance for the help.

2 REPLIES 2

The following could work if you would have a csv that would look like that:

repair.csv
garageID;garageName;vehicleID
1;XZ Garage;[20,21,22]
2;AB Garage;[20,23]

Then try that:

LOAD CSV WITH HEADERS FROM "file:///repair.csv" AS csvLine FIELDTERMINATOR ';'
UNWIND split(csvLine.vehicleID,',') AS vehicleIDs
WITH csvLine, replace(vehicleIDs,'[','') AS vehicleIDs
WITH csvLine, replace(vehicleIDs,']','') AS vehicleIDs
MERGE (g:Garage {id:csvLine.garageID})
SET g.name = csvLine.garageName
WITH g, vehicleIDs
MERGE (v:Vehicle {id:vehicleIDs})
MERGE (v)-[r:IS_REPAIRED_IN]->(g)
RETURN v, r, g

Thanks for the solution. I've successfully completed that task Saw it on another post!