Search code examples
neo4jcyphergraph-databasesmemgraphdbopencypher

How to find all nodes between two nodes in graph database?


I`m using Cypher query language and I need to find nodes between node A and E. (A->B->C->D->E)

Next query returns all nodes including A and E, but i need to exclude them, to have B, C, D nodes. How can I filter my query result?

MATCH p= (A:City{name: 'City1'})-[:LINKED*]->(E:City{name: "City5"}) return nodes(p)

Solution

  • There are a number of ways you might do this, but a simple option is to just index into the node list using:

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