密码查询从一个节点获取所有关系,并将它们附加到另一个节点 [英] Cypher query to take all relationships from one node, and attach them to another node
问题描述
我的问题是..给定两个节点,节点A&节点B是否存在密码查询,该查询可从节点A删除所有关系并将其附加到节点B, 这样以前连接到节点A的所有节点现在都连接到节点B?
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:
鉴于我有一个使用google作为登录提供者的会员帐户(member1) 我有一个单独的会员帐户(member2),使用facebook作为登录提供商 当member1尝试连接到member2用作登录提供程序的同一facebook帐户时 和member1请求合并(合并帐户) 和member2确认合并 然后,将member1和member2的帐户合并 剩下的一名成员将同时使用google和facebook作为登录提供者.
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.
执行此操作的密码查询是什么?
推荐答案
我知道这个线程很旧,但是我用同样的问题搜索了一下,但是在StackOverflow上没有找到解决方案.所以就在这里.
I know this thread is old but I googled the same question and didn't found a solution on StackOverflow. So here it is.
正如Michael告诉我的那样 APOC函数:
As Michael told me here You can use APOC functions :
apoc.refactor.to(relations, destination_node)
apoc.refactor.from(relations, destination_node)
具有类似的内容:
MATCH(n2:Resource {name: 'destionation-resource'})
MATCH(n:Resource {name:'source-resource'})<-[r]-()
OPTIONAL MATCH(n)-[r2]->()
CALL apoc.refactor.to(r, n2) YIELD input, output
CALL apoc.refactor.from(r2, n2) YIELD input AS i, output AS o
RETURN *
这篇关于密码查询从一个节点获取所有关系,并将它们附加到另一个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!