使用 * 时获取端节点

Get end nodes when using *

假设我有点 a、b、c、d 并且 a->b->c->d 与 next 相关。下面是它的合并命令。

merge (a:point{id:'a'})-[:next]-(b:point{id:'b'})-[:next]-(c:point{id:'c'})-[:next]-(d:point{id:'d'}) return a, b, c, d

Neo4j image of the merge

我正在寻找的是一种获取 a 和 d 之间所有点的方法。使用下面的查询我得到了关系,但是我怎样才能得到包含 b、c 的列表?

match p=(start:point)-[:next*]-(end:point) 
   with *, relationships(p) as r 
   where start.id ='a' and end.id = 'd'
return start, r, end

你可以做到

RETURN nodes(p)[1..-1]

获取除第一个和最后一个节点之外的节点。