Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-22-2021 02:25 AM
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.
11-28-2021 12:11 AM
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
All the sessions of the conference are now available online