Change node label in neo4j

拈花ヽ惹草 提交于 2019-12-08 14:43:28

问题


I have created a node with a wrong label.
Is there any way to change node label or relationship type without re-creating it? I have tried something like

MATCH n WHERE Id(n)=14 SET n.Labels = 'Person'

but it is fault...


回答1:


You can change the nodes associated with a label but you can't change the type of a relationship. Conceptually, if you take your chicken out of one coop and put it in another you haven't altered the substance of the chicken. But by the time you take the chicken out of the oven and put it in your mouth, it's not a chicken anymore (except equivocally). You can decide to call your cat Whiskers instead of Charlie, but if you decide you want an anaconda for a pet instead of a cat, it doesn't help to give the cat a new name. Similarly, a node can be a member of different labels and remain the same node, but a relationship's type is constitutive. So: you can add and remove labels as you please, but if you want a different relationship type then what you want is really a different relationship. This is also why a relationship has exactly one type, but a node can have many labels.

Labels are arbitrary sets or bags of nodes. The grammar for changing bags has already been given, but for completeness:

MATCH (n)
WHERE ID(n) = 14 
REMOVE n:Whiskers
SET n:Charlie

MATCH (petless_and_unhappy)-[whiskers:CAT]->(petful_and_unhappy)
DELETE whiskers
CREATE (petless_and_unhappy-[sir_hiss:ANACONDA]->(peftul_and_happy)



回答2:


MATCH (n:OLD_LABEL {id:14})
REMOVE n:OLD_LABEL
SET n:NEW_LABEL

Guess this query explains itself.




回答3:


This should work for changing labels on multiple nodes simultaneously:

MATCH (n:OLD_LABEL)
WHERE ID(n) IN [7, 8]
REMOVE n:OLD_LABEL
SET n:NEW_LABEL



回答4:


Try this:

Match (n:person{name:'John Jjones'}) Set n.name = 'John Jones'


来源:https://stackoverflow.com/questions/22542802/change-node-label-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!