|| apoc.create.removeLabels - APOC 核心文档 - Neo4j 文档

apoc.create.removeLabels

详情

语法

apoc.create.removeLabels(nodes, labels) :: (node)

描述

从给定的 NODE 值中移除给定标签。

输入参数

名称

类型

描述

nodes

ANY

要从中移除标签的节点。

labels

LIST<STRING>

要从给定节点中移除的标签。

返回参数

名称

类型

描述

node

NODE

更新后的节点。

使用 Cypher 移除标签

在 Cypher 中可以动态引用标签,而无需使用 APOC。

动态移除标签的 Cypher 语法
REMOVE n:$(label)

动态计算的标签必须评估为 STRINGLIST<STRING>。欲了解更多信息,请参阅Cypher 手册 → 动态移除节点标签

使用示例

本节中的示例基于以下示例图

CREATE (jennifer:Person:US {name: "Jennifer", community: 1, partition: 4})
CREATE (karin:Person:US {name: "Karin", community: 4, partition: 2})
CREATE (mark:Person:UK {name: "Mark", community: 3, partition: 3});

以下使用 APOC 和 Cypher 移除所有节点上除了 Person 之外的所有标签

apoc.create.removeLabels
CALL db.labels()
YIELD label WHERE label <> "Person"
WITH collect(label) AS labels
MATCH (p:Person)
WITH collect(p) AS people, labels
CALL apoc.create.removeLabels(people, labels)
YIELD node
RETURN node, labels(node) AS labels
使用 Cypher 的动态标签
CALL db.labels()
YIELD label WHERE label <> "Person"
WITH collect(label) AS labels
MATCH (p:Person)
REMOVE p:$(labels)
RETURN p, labels(p) AS labels
结果
node labels

(:Person {name: "Jennifer", partition: 4, community: 1})

["Person"]

(:Person {name: "Karin", partition: 2, community: 4})

["Person"]

(:Person {name: "Mark", partition: 3, community: 3})

["Person"]

© . This site is unofficial and not affiliated with Neo4j, Inc.