cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Apoc.merge.relationship() creates duplicates

Hi! I am trying to create relationship between two nodes using apoc.merge.relationship, but it creates two same relationships, which I can see by search. I hope someone can show me what is wrong with my cypher query

UNWIND [{ 
  color:'#82abd1', direction:'true', id:'q', index:0, linkType:'a', 
  source:'46166.a690c888-e3d5-41ed-8469-79a88cce8388', status:'approved',  
  target:'46163.a690c888-e3d5-41ed-8469-79a88cce8388', type:'Applies for',  value:2 
}] AS newLink
        MATCH 
          (fNode:Node {id: newLink.source}),
          (sNode:Node {id: newLink.target})
        CALL apoc.merge.relationship(
          fNode, 
          'Label', 
          {id: newLink.id}, 
          apoc.map.clean(newLink, ['id','type'],[]), 
          sNode, 
          apoc.map.clean(newLink, ['id','type'],[])
        )
        YIELD rel
        RETURN DISTINCT 'true';
1 REPLY 1

The problem was that I was searching for relationship without specifying nodes

match (m)-[p]-(n) return p

so it found same relationship for both m and n. To avoid this I had to specify at least one of nodes

match (m {name:'firstNode'})-[p]-(n) return p