My question is.. given two nodes, node A & node B, is there a cypher query that removes all of the relationships from node A and attaches them instead to node B, so that all nodes that were previously attached to node A, are now attached to node B?
I'm sure there are many use cases for such a query, but my use case is to do with merging multiple social network logins:
Given that I have a member account (member1) using google as a sign in provider And I have a separate member account (member2) using facebook as a sign in provider When member1 attempts to connect to the same facebook account that member2 is using as a sign in provider And member1 requests a merge (merge account) And member2 confirms the merge Then the accounts for member1 and member2 will be merged And one member will be remaining using both google and facebook as a signin provider.
What is the cypher query to do this?
EDIT: there is now way, to specify relationship type dynamically. So, workaround below is limited to relationships with same type and with no properties.
Let's create some data:
We have such data right now:
Now we want to "move" relationship from
Node1
toNode2
Query:
And result is:
What we basically are done is:
The code for the alternative solution I used is below. I'm having trouble getting the unit tests to run but once they're fixed I'll post a mini project for this on github.
I know this thread is old but I googled the same question and didn't found a solution on StackOverflow. So here it is.
As Michael told me here You can use APOC functions :
And have something like :