Showing results for 
Search instead for 
Did you mean: 

Remove existing relationship and create new one


Hi Guys..

I created this following trigger to create relationship between two nodes when ever another node is inserted

    "UNWIND apoc.trigger.nodesByLabel($assignedLabels, 'Mgr) AS node
       MATCH (s:Member { empId:node.baseId }),(d:Member { empId:node.newabaseId })

      CALL apoc.merge.relationship.eager(s,,{},{}, d,{memberId:node.memberId,sponsorId:node.sponsorId,}) YIELD rel
    DETACH DELETE node",
     { phase: 'after' }):

For example

A------->B with relation property COUNTRY AS INDIA

later same A change sponsor to C

A--------->C WITH country as JPN.

Now we need to remove that Existing relationship ship and replace this one..

How can u perform this..

Is there any special trigger available for this?


I'm having a difficult time understanding exactly what you're trying to do.

Perhaps mock up a simple example at, and share it?

note: the Cypher you shared has an unclosed quote: , 'Mgr) AS node

Please try to be as specific as you can when describing your problem:

  1. What labels are you using?
  2. When ? changes, the trigger should do what?
    • Remember, the trigger only has the context of that single node being changed.
    • If you're looking to find the changed node's parent, and delete the old relationship, that's pretty easy. While it can be done with triggers, there's better ways.

To help you, we need a better idea of what your graph looks like, what will be changed, and how you want that graph to look after the change.