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? |
{} |
配置参数
该过程支持以下配置参数
| 名称 (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']);
| 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']);
| 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});
| favorites |
|---|
{"favoriteAnimal":"horse", "favoriteMusic":"classical", "favoriteColor":"green", "foo":"bar", "alpha":1} |