In this exercise we will look at the neo4j querying language Cypher.
-
Cypher is a querying language for Neo4j. It's like SQL, but deals with graph data.
-
CREATE is the Cypher keyword for creating nodes and relationships.
-
Run Neo4j and go to http://localhost:7474/browser/.
-
Create a node for each of the four provinces of Ireland.
CREATE (Leinster:Province {name: 'Leinster'}), (Munster:Province {name: 'Munster'}), ...;
-
Create a node for every county in Ireland.
CREATE (Galway:County {name: "Galway"}), (Dublin:County {name: "Dublin"}), ...;
-
Create a relationship called IN_PROVINCE_OF for each county and province.
MATCH (county:County),(province:Province) WHERE county.name = 'Antrim' AND province.name = 'Ulster' CREATE (county)-[county_in:IN_PROVINCE_OF]->(province) RETURN county_in;
-
Create a relationship called NEIGHBOUR_OF for each county and neighbouring county. You will find a list of neighbours in the file neighbours.csv. Note the pairs are directional.
-
for every pair of neighbouring counties, there should be two NEIGHBOUR_OF relationships, each directed a different way. Write a Cypher query to check for pairs of counties that have only a single NEIGHBOUR_OF relationship between them.
- Build an API using express to run the queries from the exercises.
-
Intro to Cypher from the Neo4j developer site.
-
What is Cypher? from the Neo4j manual.