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

Adding flights to Neo4j


Since we have identified flights as entities, we will create them as nodes. To begin with, we should create a uniqueness constraint on the property code for the label :Flight as shown:

neo4j-sh (?)$ CREATE CONSTRAINT ON (flight:Flight) ASSERT flight.code IS UNIQUE;

The output is as follows:

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

We can create a flight with its information as a standalone entity:

neo4j-sh (?)$ CREATE (flight:Flight {code:"AA9", carrier:"American Airlines", duration:314, source_airport_code:"JFK", departure:1300, destination_airport_code:"LAX", arrival:114}) RETURN flight.code as flight_code, flight.carrier as carrier, flight.source_airport_code as from, flight.destination_airport_code as to;

The output is as follows:

+---------------------------------------------------+
| flight_code | carrier             | from  | to    |
+---------------------------------------------------+
| "AA9"       | "American Airlines...