2
votes

I have a problem with relations on Neo4j. I have 3 files with the .csv extension to be loaded into Neo4j. The first two files are nodes that I already and successful created. The files are: forum_0.csv & person_0.csv and they got this headers:

idForum|titleForum|creationDateForum (forum_0.csv)

idPerson|firstNamePerson|lastNamePerson| ... (person_0.csv)

I successful create the two nodes but now I need to create a relation between these nodes. For that I need to load the third file, forum_hasMember_person_0.csv (and this file got this header: idForum|idPerson|joinDateFHMP )

and my problem is at this point. I load the third file with this code:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS
FROM ".../forum_has_Member_person_0.csv" AS row
FIELDTERMINATOR "|"
MATCH (forum:Forum(idForum: row.idForum))
MATCH (person:Person(idPerson: row.idPerson))
MERGE (forum)-[:FOR_HASMEMBER_PRS]->(person);

How can I create the FOR_HASMEMBER_PRS relation with "joinDateFHMP" property? It's the only thing left on the relationship creation. How can I solve this?

2

2 Answers

1
votes

Does this work for you? I have also fixed some typos in your question's query.

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS
FROM ".../forum_has_Member_person_0.csv" AS row
FIELDTERMINATOR "|"
MATCH (forum:Forum {idForum: row.idForum})
MATCH (person:Person {idPerson: row.idPerson})
MERGE (forum)-[:FOR_HASMEMBER_PRS {joinDateFHMP: row.joinDateFHMP}]->(person);
2
votes

I like putting an identifier on the relationship and then using SET:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS
FROM ".../forum_has_Member_person_0.csv" AS row
FIELDTERMINATOR "|"
MATCH (forum:Forum {idForum: row.idForum})
MATCH (person:Person {idPerson: row.idPerson})
MERGE (forum)-[r:FOR_HASMEMBER_PRS]->(person)
SET r.joinDateFHMP = row.joinDateFHMP;