带有文字映射语法的密码查询 &动态键 [英] Cypher query with literal map syntax & dynamic keys
问题描述
我想做一个生成特定 json 输出的密码查询.此输出的一部分包括一个对象,该对象具有相对于父节点的子节点的动态数量的键:
I'd like to make a cypher query that generates a specific json output. Part of this output includes an object with a dynamic amount of keys relative to the children of a parent node:
{
...
"parent_keystring" : {
child_node_one.name : child_node_one.foo
child_node_two.name : child_node_two.foo
child_node_three.name : child_node_three.foo
child_node_four.name : child_node_four.foo
child_node_five.name : child_node_five.foo
}
}
我尝试创建一个密码查询,但我不相信我已经接近实现上述所需的输出:
I've tried to create a cypher query but I do not believe I am close to achieving the desired output mentioned above:
MATCH (n)-[relone:SPECIFIC_RELATIONSHIP]->(child_node)
WHERE n.id='839930493049039430'
RETURN n.id AS id,
n.name AS name,
labels(n)[0] AS type,
{
COLLECT({
child.name : children.foo
}) AS rel_two_representation
} AS parent_keystring
我曾计划让 children.foo 计算父母的每个特定关系/孩子出现的次数.有没有办法利用reduce功能?基于分析下面建议的数组,报告会在哪里生成?即报告将是一个 json 对象,其中每个键是一个不同的 RELATIONSHIP,属性值将是该关系源自父节点的次数?
I had planned for children.foo to be a count of how many occurrences of each particular relationship/child of the parent. Is there a way to make use of the reduce function? Where a report would generate based on analyzing the array proposed below? ie report would be a json object where each key is a distinct RELATIONSHIP and the property value would be the amount of times that relationship stems from the parent node?
非常感谢您提供指导.
推荐答案
我不确定 Cypher 是否会让您使用变量来确定对象的键.使用数组对你有用吗?
I'm not sure that Cypher will let you use a variable to determine an object's key. Would using an Array work for you?
COLLECT([child.name, children.foo]) AS rel_two_representation
这篇关于带有文字映射语法的密码查询 &动态键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!