Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-09-2019 08:49 PM
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.
12-09-2019 05:54 AM
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
12-12-2019 08:21 AM
Thanks for the solution. I've successfully completed that task Saw it on another post!
All the sessions of the conference are now available online