Book Image

Neo4j Graph Data Modelling

Book Image

Neo4j Graph Data Modelling

Overview of this book

Table of Contents (16 chapters)
Neo4j Graph Data Modeling
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Queries to find journeys and bookings


With the data on bookings added in, we can now explore some interesting queries that can help us.

Finding all journeys of a user

All journeys that a user has undertaken will be all journeys that they have been a passenger on. We can use the user's e-mail to search for journeys on which the user has been a passenger.

To find all the journeys that the user has been a passenger on, we should find the journeys via the bookings, and then using the bookings, we can find the journeys, flights, and cities as shown:

neo4j-sh (?)$ MATCH (b:Booking)-[:HAS_PASSENGER]->(p:Passenger{email:"[email protected]"})
WITH b
MATCH (b)-[:HAS_JOURNEY]->(j:Journey)-[:BY_FLIGHT]->(f:Flight)
WITH b._id as booking_id, j.date_of_journey as date_of_journey, COLLECT(f) as flights ORDER BY date_of_journey DESC
MATCH (source:City)-[:HAS_FLIGHT]->(f)-[:FLYING_TO]->(destination:City)
WHERE f in flights
RETURN booking_id, date_of_journey, source.name as from, f.code as by_flight...