在JSON对象中输出所有直接邻居 [英] Output all direct neighbours in a JSON object

查看:63
本文介绍了在JSON对象中输出所有直接邻居的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以用Cypher编写查询以将以下查询的输出格式化为JSON对象?

Is it possible to write a query in Cypher to format the output of the following query into a JSON object?


MATCH (n:Artist{name:'Metallica'})-[r]->(m:Album)
RETURN {node: n, neighbours: { type(r): collect(m) }}

当然,这不是有效的Cypher查询.我正在尝试查看是否有任何方法可以编写生成此处提出的概念的查询?另一个问题(type(r):除外)是m,它需要按type(r)分组.

Of course, this is not a valid Cypher query. I'm trying to see if there's any way to write a query that generates the concept proposed here? One another problem (other than type(r):) is with m and it needs to be grouped by type(r).

推荐答案

Gabor Szarnyas 所述,在当前实现中密码是不可能完全按照您的意愿进行的.但是您可以使用用户定义的过程 apoc.map.fromPairs APOC 库:

As Gabor Szarnyas said, in the current implementation of the cypher it is impossible to do exactly as you wish. But you can do it using user defined procedure apoc.map.fromPairs from APOC library:

MATCH (n:Artist {name:'Metallica'})-[r]->(m:Album)
WITH n, type(r) AS relType, collect(m) AS albums
WITH n, collect([relType, albums]) as pairs
CALL apoc.map.fromPairs( pairs ) YIELD value as neighbours
RETURN { node: n, neighbours: neighbours }

这篇关于在JSON对象中输出所有直接邻居的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆