小编Rom*_*eee的帖子

neo4j Cypher分层树构建对JSON的响应

你能帮我构建一下密码查询吗?我有以下图形数据库结构:

(parent:Category)-[:subcategory]->(child:Category)
Run Code Online (Sandbox Code Playgroud)

使用此图数据,我具有深层次的分层树.

我在Stackoverfllow.com上找到了以下代码并更改了我的数据:

MATCH (root:Category)-[:subcategory]->(parent:Category)-[:subcategory]->(child:Category)
WITH root, {category: parent, children: collect(child)} AS parent_with_children
WHERE NOT(()-[:subcategory]->(root))
RETURN {category: root, children: collect(parent_with_children)}
Run Code Online (Sandbox Code Playgroud)

但他只对3级树的深度构建响应.我需要更大.我试着像这个例子一样构建json响应:

  [
    category: {
      name: "PC"
      children: {
        category: {
          name: "Parts"
          children: {
            category: {
              name: "CPU"
              ...
            }
          }
        },
        category: {
          name: "Accessories"
          ...
        }
      } 
    }, 
    category: {
      name: "Laptop"
      ...
    }
  ]
Run Code Online (Sandbox Code Playgroud)

Cypher可以进行递归调用吗?我认为这会更好.

谢谢.

PS我知道在SO上有类似的问题,但他们没有帮助我.

neo4j neo4j.rb

1
推荐指数
1
解决办法
941
查看次数

标签 统计

neo4j ×1

neo4j.rb ×1