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:
Note
We can add more hotels from the hotels.cqy
file that can be downloaded along with the code for this chapter.