hi,
in my Neo4j graph I have internet usernames which connected to persons like this:
(username) <- [has_username] - (person)
while I am loading the incremental data a few scenarios might be.
let's take the username: abc1234 for example
abc1234 can be multiple times in the DB while each abc1234 has it's own unique id property.
for example:
abc1234 with property unique id = 1 belong to person x
abc1234 with property unique id = 2 belong to person y
sometimes there a abc1234 which is still not connected to any person.
I am trying to use cypher in order to load the usernames csv file as follows:
CALL apoc.periodic.iterate(
"
LOAD CSV FROM 'file:///neo4j/UserName.csv' AS line with line where line[0] is not null with line[0] as id, line[1] as userName, line[2] as idNumber, line[4] as status, line[5] as startDate, line[6] as endDate
RETURN id, userName, idNumber, status, startDate, endDate
",
"
MERGE(un:UserName {userName: userName})
ON CREATE set un.id=id, un.userName=userName, un.idNumber=idNumber, un.status=status, un.startDate=startDate, un.endDate=endDate
with un
MATCH(un)
OPTIONAL MATCH (un)<-[:HAS_USERNAME]-(n:IdNumber)
with un, n, case when n is null then true else false end as hasusername
case
when hasusername then
set un.id=id, un.userName=userName, un.idNumber=idNumber, un.status=status, un.startDate=startDate, un.endDate=endDate
else
set un.status=status, un.endDate=endDate
end
" ,
{batchSize:5000, parallel:False}
);
what I am trying to do is basically create UserName node when it's not exists or
if it does exists and has a relationship with a person , I want to match it and change 2 properties or
if it does exists and has no relationship with a person, I want to match it and change all properties.
my query isn't working for no matter what, may I get some help from you guys please? :)
thank you!!!