I am using neo4j 4.1.3. I have 2 labels : Person and Rec. I need to create a relationship between these 2 only when there exists exactly one person with that last name. When I run the below, relationships are created for all persons with that last name. My code is below:
MATCH (echk:REC {id: 'abcdef'})
OPTIONAL MATCH (p:Person) WHERE
p.name CONTAINS 'Shirley'
WITH p, echk, count(p) as personcnt
where personcnt=1
CALL apoc.merge.relationship(p, 'Test', {}, {}, echk, {}) YIELD rel
RETURN p, echk, rel
I have 33 people with "Shirley' and 33 relationships are getting created with that REC. However, there should be no relationship because personcnt <> 1. When I just write
OPTIONAL MATCH (p:Person) WHERE
p.name CONTAINS 'Shirley' return count(p) -> I get 33 as the value. I am not sure why my where condition is not kicking in.