I can't find a way to change a relationship type in Cypher. Is this operation possible at all? If not: what's the best way achieve this result?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Unfortunately there is no direct change of rel-type possible at the moment.
You can do:
MATCH (n:User {name:"foo"})-[r:REL]->(m:User {name:"bar"})
CREATE (n)-[r2:NEWREL]->(m)
// copy properties, if necessary
SET r2 = r
WITH r
DELETE r
回答2:
The answer from Michael Hunger
is correct but it still need with
in this cypher query.
WITH
can be used when you want to switch different operation in one cypher query.
http://docs.neo4j.org/chunked/stable/query-with.html
MATCH (n:User {name:"foo"})-[r:REL]->(m:User {name:"bar"})
CREATE (n)-[r2:NEWREL]->(m)
SET r2 = r
WITH r
DELETE r
回答3:
You can't, the type of a relationship is constitutive or essential, as opposed to node labels which are arbitrary bags to group nodes. (See this q/a for an analogy.) You have to create the new relationship, delete the old (and copy properties if there are any).
回答4:
I use the following when modifying it.
match (from:Label1 { prop: 1 })-[r:RELATIONSHIP]->(to:Label2 { prop: 2 })
with from, r, to
create (from)-[:NEW_RELATIONSHIP]->(to)
with r
delete r