I currently have a query that builds a relationship between Men nodes and People nodes:
MATCH (m:Mem)
UNWIND m.personID as person
MERGE (p:Person{personID:person})
MERGE (m)-[:WITH]->(p)
The Mem nodes contain an array of PersonIDs that I am unwinding and then matching to the Person nodes with the corresponding PersonIDs. However, the query is building the relationship with new Person nodes that it creates, with just the corresponding personIDs property (and no other properties) instead of building the relationship with the existing Person nodes with the corresponding personIDs.
This is happening even though I have a unique constraint on the personID property for nodes with the Person label.
How can I write a query that build the relationships but doesn't create new nodes with the corresponding personIDs?
MERGE
(instead ofCREATE
) for thePerson
node, you would only be creating a newPerson
node if there is no node with the samepersonID
value. You need to check why the expectedPerson
nodes do not already exist. – cybersam