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

apoc.create.removeProperties

详情

语法

apoc.create.removeProperties(nodes, keys) :: (node)

描述

从给定 `NODE` 值中移除指定属性。

输入参数

名称

类型

描述

nodes

ANY

要移除属性的节点。

keys

LIST<STRING>

要从给定节点中移除的属性键。

返回参数

名称

类型

描述

node

NODE

更新后的节点。

使用 Cypher 移除属性

在 Cypher 中可以动态引用属性,无需使用 APOC。

动态移除节点或关系属性的 Cypher 语法
REMOVE n[key]

动态计算的键必须解析为 `STRING` 值。更多信息请参见 Cypher 手册 → 动态移除属性

使用示例

本节示例基于以下示例图谱

CREATE (jennifer:Person {name: "Jennifer", community: 1, partition: 4})
CREATE (karin:Person {name: "Karin", community: 4, partition: 2})
CREATE (elaine:Person {name: "Elaine", community: 3, partition: 3})
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-06-01")}]-(karin)
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-05-04")}]-(elaine);

我们可以使用 APOC 和 Cypher 删除 `Person` 节点中除 `name` 以外的所有属性

apoc.create.removeProperties
CALL db.propertyKeys()
YIELD propertyKey WHERE propertyKey <> "name"
WITH collect(propertyKey) AS propertyKeys
MATCH (p:Person)
WITH collect(p) AS nodes, propertyKeys
CALL apoc.create.removeProperties(nodes, propertyKeys)
YIELD node
RETURN node;
使用 Cypher 的动态属性
CALL db.propertyKeys()
YIELD propertyKey WHERE propertyKey <> "name"
WITH collect(propertyKey) AS propertyKeys
MATCH (p:Person)
FOREACH (key IN propertyKeys | REMOVE p[key])
RETURN DISTINCT p
结果
node

(:Person {name: "Jennifer"})

(:Person {name: "Karin"})

(:Person {name: "Elaine"})

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