apoc.create.virtual.fromNodeExtended

函数 Apoc 扩展

apoc.create.virtual.fromNodeExtended(node, [propertyNames]) 根据现有节点创建一个虚拟节点,且仅包含请求的属性

签名

apoc.create.virtual.fromNodeExtended(node :: NODE?, propertyNames :: LIST? OF STRING?, additionalProperties :: MAP, ?config :: MAP?) :: (NODE?)

输入参数

名称 类型 默认

节点

NODE?

null

propertyNames

LIST? OF STRING?

null

additionalProperties

MAP?

{}

config

MAP?

{}

配置参数

该过程支持以下配置参数

表 1. 配置参数
名称 (name) type 默认 description(描述)

wrapNodeIds

boolean

false

默认情况下,此函数会将节点的 ID 更改为负数,以代表虚拟节点。我们可以将其设置为 true 以保留原始 ID。

使用示例

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

CREATE (a:Account {type: 'checking', ownerName: 'Maria Perez', ownerId: '123456789', accountNumber: 101010101, routingNumber: 10101010, amount: 1000.00, bank: 'Best Bank'});
CREATE (p:Person {name: 'Jane Doe', birthdate: date('1990-01-13'), favoriteColor: 'green', favoriteDessert: 'ice cream', favoriteMusic: 'classical', favoriteBand: 'The Beatles', favoriteVacation: 'beach', favoriteAnimal: 'horse', favoriteBeverage: 'coffee', favoriteFlower: 'lily'});

apoc.create.virtual.fromNodeExtended 过程提供了一种仅可视化或返回所需数据的方法,从而隐藏任何不必要或敏感的信息。

下面的示例展示了如何使用该过程仅从上述节点返回非敏感属性

apoc.create.virtual.fromNodeExtended
MATCH (a:Account {accountNumber: 101010101})
RETURN apoc.create.virtual.fromNodeExtended(a, ['type','bank']);
表 2. 结果
account

{"type":"checking","bank":"Best Bank"}

apoc.create.virtual.fromNodeExtended 过程还可用于简化具有大量属性的节点,仅显示对查询重要的属性。

下面的示例展示了此用法

apoc.create.virtual.fromNodeExtended
MATCH (p:Person {name: 'Jane Doe'})
RETURN apoc.create.virtual.fromNodeExtended(p, ['favoriteColor','favoriteAnimal','favoriteMusic']);
表 3. 结果
favorites

{"favoriteAnimal":"horse", "favoriteMusic":"classical", "favoriteColor":"green"}

我们还可以通过第 3 个参数设置附加属性。下面的示例展示了此用法

apoc.create.virtual.fromNodeExtended
MATCH (p:Person {name: 'Jane Doe'})
RETURN apoc.create.virtual.fromNodeExtended(p, ['favoriteColor','favoriteAnimal','favoriteMusic'], {foo: 'bar', alpha: 1});
表 4. 结果
favorites

{"favoriteAnimal":"horse", "favoriteMusic":"classical", "favoriteColor":"green", "foo":"bar", "alpha":1}

封装节点

默认情况下,此函数会将节点的 ID 更改为负数,以代表虚拟节点。若要保留原始 ID,请使用配置项 { wrapNodeIds: true }

apoc.create.virtual.fromNodeExtended
CREATE (p:Person {name: 'Jane Doe'})
WITH apoc.create.virtual.fromNodeExtended(p, ['name'], {}, { wrapNodeIds: true }) AS node
RETURN id(node) AS id;
表 5. 结果
id

1

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