我对Neo4j的关系有问题。我有3个扩展名为.csv的文件加载到Neo4j中。前两个文件是我已经成功创建的节点。文件是:forum_0.csv& person_0.csv他们得到了这个标题:
idForum | titleForum | creationDateForum(forum_0.csv)
idPerson | firstNamePerson | lastNamePerson | ......(person_0.csv)
我成功创建了两个节点,但现在我需要在这些节点之间创建关系。为此我需要加载第三个文件forum_hasMember_person_0.csv (这个文件有这个标题: idForum | idPerson | joinDateFHMP)
我的问题就在这时。我用这段代码加载第三个文件:
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);
如何使用“joinDateFHMP”属性创建FOR_HASMEMBER_PRS关系? 这是创造关系的唯一因素。我该如何解决这个问题?
答案 0 :(得分:2)
我喜欢在关系上放置一个标识符,然后使用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;
答案 1 :(得分:1)
这对你有用吗?我还在你问题的查询中修正了一些拼写错误。
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);