Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
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 (11) Chapters Close

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

Adding hotels to airports


Now that we have airports as nodes, we can add hotels to our data model. As discussed earlier, hotels have an ID, name, and average price.

Let's start by adding a constraint on the ID of the hotel, which is the _id property, as shown:

neo4j-sh (?)$ CREATE CONSTRAINT ON (hotel:Hotel) ASSERT hotel._id IS UNIQUE;

The output of the preceding query is as shown:

+-------------------+
| No data returned. |
+-------------------+
Constraints added: 1

We can add a hotel and connect it to the JFK airport using the following query:

neo4j-sh (?)$ CREATE (hotel:Hotel {_id:"6ad8ce6e-1c0e-11e5-8db1-6c40089a9424",  name:"Hilton", price: 180})
WITH hotel
MATCH (airport:Airport{code:"JFK"})
WITH airport, hotel
MERGE (airport)-[:HAS_HOTEL]->(hotel)
RETURN airport, hotel;

The output of the preceding query is as follows:

Figure 5.8: Airport hotels

Note

We can add more hotels from the hotels.cqy file that can be downloaded along with the code for this chapter.

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 €18.99/month. Cancel anytime