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.

Create a linked list for each bus-route

Hi! I'm new to Neo4j, I'm currently migrating a lot of geospatial data from SQL and I'm a bit stuck on declaratively creating bus routes.

So far I have 60k bus-routes with the following relevant properties

stop_sequence: 1    // increasing integer with one being the start and n being the end outbound
route: 700                // a route-id integer, a route is an id for a bus-route for a particular operator
operator: Aircoach  // a bus-operator ID
direction: Inbound // or Outbound

I'd like to connect each (operator,route) series of BusRoute nodes in order with the relationship direction depending on the direction field's value. I assume this is possible but I can't figure out how based on other linked list questions and documentation. Any help would be appreciated!

1 REPLY 1


    await db.run(`
    match(s0:BusRoute), (s1:BusRoute)
    where s0.route = s1.route and s0.stopSequence = s1.stopSequence + 1
      and s0.direction = 'Outbound' and s1.direction = 'Outbound'
      and s0.operator = s1.operator
      merge (s1)-[:DRIVES_TO]->(s0)
    `)
    await db.run(`
    match(s0:BusRoute), (s1:BusRoute)
    where s0.route = s1.route and s0.stopSequence = s1.stopSequence + 1
      and s0.direction = 'Inbound' and s1.direction = 'Inbound'
      and s0.operator = s1.operator
      merge (s0)-[:DRIVES_TO]->(s1)
    `)

I believe this cartesian product works!