我正在尝试编写一个密码查询,其中收集所有相关节点并在地图中的密钥下返回:
{
name: 'chart',
CONTAINTED: [
{
name: 'id'
},
{
name: 'bloodpressure'
},
...
],
FOREIGNKEY: [
{
name: 'clientid'
}
]
}
我尝试使用以下cypher查询执行此操作,但它不太正确。使用下面的方法返回两个记录而不是一个。
MATCH path=(table:tabPHI {name: 'client'})-[r]-(c)
WITH table as tab, type(r) as rel, collect(c) as col
CALL apoc.map.setKey(tab, rel, col) YIELD value as foo
return foo
答案 0 :(得分:1)
MATCH (table:tabPHI {name: 'client'})-[r]-(c)
WITH table as tab, type(r) as rel, collect(c) as col
WITH tab, COLLECT(rel) AS keys, COLLECT(col) AS values
WITH keys(tab) as main_keys, [key IN keys(tab)|tab[key]] AS main_values, keys, values
CALL apoc.map.fromLists(main_keys + keys, main_values + values) YIELD value as foo
return foo
您正在为查询中的每种关系类型创建一个地图。您必须在某个时刻COLLECT(rel)
为每个标签获得一个结果。