重定向关系
APOC 库包含可用于将关系重定向到目标节点的程序。
重定向关系的程序
| 限定名称 | 类型 |
|---|---|
|
过程 |
|
过程 |
示例
以下示例将进一步解释此程序。
重定向目标节点
以下内容创建了由
FOOBAR 关系连接的 Foo 和 Bar 节点,以及一个单独的 Antony 节点CREATE (f:Foo {value: "Foo"})-[rel:FOOBAR {a:1}]->(b:Bar {value: "Bar"})
CREATE (p:Person {name:'Antony'})
RETURN *
以下内容会将
FOOBAR 关系的目标节点从 Bar 节点更改为 Antony 节点MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
MATCH (p:Person {name:'Antony'})
CALL apoc.refactor.to(rel, p, { failOnErrors = true })
YIELD input, output
RETURN input, output
如果运行上述查询,将得到以下图形
重定向源节点
以下内容创建了由
FOOBAR2 关系连接的 Foo2 和 Bar2 节点,以及一个单独的 David 节点CREATE (f:Foo2 {value: "Foo2"})-[rel:FOOBAR2 {a:1}]->(b:Bar2 {value: "Bar2"})
CREATE (p:Person {name:'David'})
RETURN *
以下内容会将
FOOBAR2 关系的源节点从 Foo 节点更改为 David 节点MATCH (f:Foo2)-[rel:FOOBAR2 {a:1}]->(b:Bar2)
MATCH (p:Person {name:'David'})
CALL apoc.refactor.from(rel, p, { failOnErrors = true })
YIELD input, output
RETURN input, output
如果运行上述查询,将得到以下图形