刚接触图数据库,请问如何查找某个点的所有子孙?

刚了解图数据库,还有许多概念不清楚,想从一个实际的场景入手,但还是一头雾水,希望各位大佬解答一下 :rofl:

CREATE TAG IF NOT EXISTS File(
    id int,
    name string
);

CREATE EDGE IF NOT EXISTS Parent(
    pid int
);

好像查出来了 :joy:

Match (f:File)-[e:Parent*]->(a:File{id:6}) return a,e

建议 id 作为 vertexid(vid)
条件用 where id(a) == 6

1 个赞

Cool !

最后语句改为了

Match (f:File)-[e:Parent*]->(a) where id(a) == 6 return f.File.id

请问,我如果要查找某个文件的所有祖宗节点,使用下面的语句:

match (f:File {id: 6})-[e:Parent*0..]->(p) return p

也就是向上递归有啥建议吗?

好像可以解决我的第二个问题

MATCH (f:File{id:17})-[e:Parent*]->(n)  RETURN distinct n.File.id;

File{id: 17} 是基于索引,这里如果你的起始条件都是 id,那么你不需要索引,用 id(f) == 17 就是不需要索引的。

索引是有代价的。

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。