小编Son*_*ata的帖子

如何在Neo4j中映射树结构?

我正在努力描述Neo4j中的树结构数据集.在我当前的模型中,一个节点可以有n个链接到其他节点,使其成为这些节点的子节点:

root
 |
 \-- A
     |
     \-- 1
     |
     \-- 2
Run Code Online (Sandbox Code Playgroud)
  • 指向root的链接
  • 1和2链接到A.
  • root是A的父级
  • 1和2是A的孩子

因为我使用的是nodejs(带有node-neo4j),所以读取数据库仅限于使用Cypher.要读取节点,我使用以下查询:

START n=node(1)
    -- this is the root node

MATCH (n)<-[linkedby:links*]-x, x-[linksto?:links*1]->()
    -- get all nodes that link to the root node and all nodes linking to those nodes, etc, etc and retrieve all nodes those found nodes link to

RETURN n, x, linkedby, LAST(linkedby) AS parent, COLLECT(DISTINCT linksto) AS links      
    -- the last in the path of linkedby is the …
Run Code Online (Sandbox Code Playgroud)

tree neo4j cypher

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

标签 统计

cypher ×1

neo4j ×1

tree ×1