cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Shortest Path Between 2 nodes and Test Nodes.property

I am trying to learn Neo4j. I will like to model the subway network. The schema of a subway station look like this:

{
"identity": 0,
"labels": [
"Station"
],
"properties": {
"name": "station-ew-01",
"line": [
"ew"
]
}
}

"ew" in the "line" property represents the the line the station is on. Some stations will have multiple lines running through the station.

I did a cypher query to find the shortest path between 2 nodes:

match path = shortestpath((start:Station {name:"source"})-["TRAVEL_TO*1..30]->(end:Station {name:"destination"}))

return path

How do I construct a cypher query such that the nodes/"stations" from "source" to "destination", are on the same line ? How do I specify node.lines = "ew" for each of the node return by the shortest path ?

Thanks.

1 REPLY 1

Hi @demoacct01 ,

You can try out the below cypher query to get the stations on the same line:

match path = shortestpath((start:Station {name:"source"})-["TRAVEL_TO*1..30]->(end:Station {name:"destination"}))
where start.line=end.line
return path;

Also if you want to specify line='ew' you can put that in the where condition see the below query:

match path = shortestpath((start:Station {name:"source"})-["TRAVEL_TO*1..30]->(end:Station {name:"destination"}))
where start.line=end.line and start.line='ew' and end.line='ew'
return path;

Let me know if this works for you