I created two sets of nodes: person and location. Now I want to relate every person to one or many locations (1:N). A person is matching to a location where personPK = FKperson. I used the following cypher scripts but neither of them worked.
// script A
MATCH (p:Person {personPK: personPK})
MATCH (l:Location {FKperson: FKperson})
MERGE (p)-[rel: VISITED]->(l)
RETURN count(rel);
// script B
MATCH (p: Person), (l: Location)
WHERE p.personPK = l.FKperson
MERGE (p)-[rel: VISITED]->(l)
RETURN count(rel);
Couldn't find a thread about this, seems to be to simple. But I would appreciate some help, thanks.
Thanks @koji
But you created a relationship 1:1 and my challenge is a 1:N. Meaning: one Person can have visited more than one location. This might be the cause why my script B isn't working.
I also tried the following script C, but it just generates new nodes in relation 1:1. The task to connect existing nodes 1:N according to PK/FK is not performed.
Thanks @koji
I found my mistake. As I imported the data for the location nodes I forgot to change the format of FKperson to integer like this
"toInteger(row[5]) AS FKperson"
After I changed the format of FKperson the following script worked well, even for the 1:N relationship:
MATCH (p: Person), (o: Location)
WHERE p.personPK = o.FKperson
MERGE (p)-[rel: VISITED]->(o)
RETURN count(rel)