在 Neo4j 中更改节点标签 [英] Change node label in neo4j

查看:147
本文介绍了在 Neo4j 中更改节点标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个标签错误的节点.
有没有办法在不重新创建的情况下更改节点标签或关系类型?我尝试过类似

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

匹配 n,其中 Id(n)=14 SET n.Labels = 'Person'

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

但它是错的...

推荐答案

您可以更改与标签关联的节点,但不能更改关系的类型.从概念上讲,如果您将鸡从一个鸡舍中取出并放入另一个鸡舍中,那么您并没有改变鸡的物质.但是当你把鸡肉从烤箱里拿出来放进嘴里时,它就不再是一只鸡了(除了模棱两可).您可以决定称您的猫 Whiskers 而不是 Charlie,但是如果您决定要为宠物而不是猫使用蟒蛇,那么给猫的新名字.类似地,一个节点可以是不同标签的成员并保持相同的节点,但关系的类型是构成性的.所以:您可以随意添加和删除标签,但如果您想要不同的关系类型,那么您真正想要的是一种不同的关系.这也是为什么一个关系只有一种类型,而一个节点可以有多个标签.

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)

这篇关于在 Neo4j 中更改节点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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