I am using UNWIND to create multiple nodes in NEO4j. The problem is if one of the node is a duplicate it will be rejected and the entire query fails. I want to be able to create multiple relationship between the same nodes if they already exist..e.g a friend could receive multiple invitations from the same person. So I have an array of objects [{email: [email protected]},{email:[email protected]},...] to be invited and the email of the sponsor sponsorEmail. There is constraint on email so attempts to create a duplicate will fail and reject the entire query. The following works fine when there is no duplicate.
MATCH (s {email: '[email protected]'})
UNWIND $arrayOfObjects as invitees
CREATE (i:Invitee) MERGE (s)-[r:INVITED {since: timestamp()}]->(i)
SET i=invitees
I have tried substituting MERGE the CREATE thinking that the MERGE would find a MATCH and proceed to CREATE the relationship but it did not work..I still get duplicate error. Short of cleaning the arrayOfObjects before executing the query is there another way to do this? What I want is for the duplicate not to fail but to create a relationship with the existing Invitee node.