Skip to main content
TuringDB’s shortestPath processor runs a Dijkstra search from a source set of nodes to a target set of nodes, returning the shortest distance and the path taken based on a numeric edge weight property.

Sample dataset

The examples on this page use a small railway network. Run the following query to create it:

Syntax

Basic usage

Returning only the distance or only the path

Both output variables are always computed — you can choose to return one or both:

Multiple sources or targets

You can pass multiple nodes to the source or target set — shortestPath will find the shortest distance across all combinations and return the best one:

Limitations

Any variable on a pattern going into a shortestPath processor cannot be returned in the RETURN clause — they are consumed by the processor. The following query will produce an error:
You can still MATCH additional nodes outside of the source and target sets and include them in RETURN. The result will be a cartesian product with the shortest path output: