Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Neo4j Graph Data Modelling

You're reading from   Neo4j Graph Data Modelling Design efficient and flexible databases by optimizing the power of Neo4j

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781784393441
Length 138 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Mahesh K Lal Mahesh K Lal
Author Profile Icon Mahesh K Lal
Mahesh K Lal
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Neo4j Graph Data Modeling
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Graphs Are Everywhere FREE CHAPTER 2. Modeling Flights and Cities 3. Formulating an Itinerary 4. Modeling Bookings and Users 5. Refactoring the Data Model 6. Modeling Communication Chains 7. Modeling Access Control 8. Recommendations and Analysis of Historical Data 9. Wrapping Up 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images