Neo4j Cypher:复制关系和删除节点 [英] Neo4j Cypher: copy relationships and delete node

查看:85
本文介绍了Neo4j Cypher:复制关系和删除节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将节点 (n) 的所有内部关系复制到另一个节点 (m)(两个我都知道 ID 的女巫),然后再删除 (n),但我想不出代码.关系可能存在也可能不存在.

I'm trying to copy all inward relationships of a node (n) to another node (m) (both of witch I know the ids) before deleting (n), but I couldn't come up with the code. The relationships may or may not exist.

有人摘录吗?

推荐答案

您将无法从关系集合内部动态创建关系类型.

You wont be able to create a relationshiptype dynamically from inside a collection of relationships.

假设即使我们收集所有传入的关系如下

Suppose even if we collect all the incoming relationships as below

START n=node(id1) MATCH n<-[r]-() WITH collect(r) as rels ...

您可以遍历集合 rels,但不能在下面执行

You would be able to iterate over the collection rels but WOULD NOT be able to do below

CREATE (n)-[rels[i]]->(m)

因此,假设所有传入的关系都属于同一类型,请说foo".然后您可以执行以下操作.

So assuming if all incoming relationships are of same type say 'foo'. Then you could do the following.

START n=node(id1),m=node(id2) 
MATCH n<-[r:foo]-(p) 
WITH collect(p) as endNodes,m
FOREACH(i in range(0,length(endNodes)-1) | foreach(a in [endNodes[i]] | 
 create m<-[:foo]-a 
))

如果您的 relationshipTypes 不同,那么您可以参考此解决方法:这里.您可以从控制台查询,将所有 startnode ,endnode,relationshiptype 信息作为 csv 下载到 Excel 表中.然后运行密码脚本从它运行.

In case if your relationshipTypes are different, then you can refer this workaround technique :here. You can query from the console, download all startnode , endnode, relationshiptype info as csv into excel sheet. And then run cypher script to run from it.

另一种方法是您可以使用 java api for neo4j 进行查询,然后存储所有关系和节点,相应地构建您的查询并再次回火.

Other way is you can query using java api for neo4j and then store all the relationships and nodes , frame your queries accordingly and fire back again.

这篇关于Neo4j Cypher:复制关系和删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆