更新标签

要向节点添加或删除标签,请使用 .set.remove 与节点方法 .label

添加标签

const movie = new Cypher.Node();
const clause = new Cypher.Match(new Cypher.Pattern(movie)).set(movie.label("NewLabel"), movie.label("Another label"));
MATCH (this0)
SET
    this0:NewLabel,
    this0:`Another Label`

移除标签

const movie = new Cypher.Node();
const clause = new Cypher.Match(new Cypher.Pattern(movie)).remove(movie.label("NewLabel"));
MATCH (this0)
REMOVE this0:NewLabel

设置动态标签

在某些情况下,需要动态定义要添加或删除的标签,例如表达式的结果。为实现此目的,.label 方法接受表达式而不是字符串。

例如,要将一个节点的所有标签复制到另一个节点,可以使用函数 labels() 作为 .label 的表达式。

new Cypher.Match(new Cypher.Pattern(movie)).set(movie.label(Cypher.labels(anotherNode)));

这正确地应用了动态标签的语法

MATCH (this0)
SET
    this0:$(labels(this1))
© . This site is unofficial and not affiliated with Neo4j, Inc.