Week 8 - Neo4j
Last updated
Last updated
This week's lab focuses on setting up and using Neo4j.
How to install and set up Neo4j
Using the Neo4j interface - Running a Neo4j demo - Running queries - Exploring a graph with the mouse - Changing node/relationship colours and labels - Understanding the "Connect result nodes" option
Planning a graph using Arrow Tool and importing it into Neo4j
You have two options to install Neo4j on your device: local setup (Section 1.1) or cloud setup (Section 1.2).
It is strongly recommended that you set up Neo4j locally if possible.
Head to to download the Neo4j desktop.
Install it the same way as you would install any other program.
After installing, open Neo4j Desktop.
Create a new "Project" by going to Projects, then clicking "Add" at the top right, and "Local DBMS". Give it a name and a password.
Once it has been created, find the newly created database in the menu and click Start. Once started, click Open and this will open your database in the Neo4j browser.
If you cannot set up Neo4j locally, you can try Neo4j Aura, a cloud-based version of Neo4j. To set up a graph:
Once your email is validated, an instance will be created for you.
In order to use the instance, click on "Open". You will be asked to type your password. You can find it in the .txt file you downloaded just now.
Make sure to copy the credentials and save them somewhere safe.
It will take a few minutes for your database to be set up.
Once set up, click on the "Neo4j Guides" button on the database. Then you can explore Neo4j.
Your first task is to familiarise yourself with the Neo4j browser interface.
In the vertical menu on the left, have a look through each of the submenus - Database, Favourites, Project Files, etc.
Take a look at Guides in particular. Check out the intro guide by clicking on the :guide intro
- it provides a nice overview of the core components of the Neo4j browser. Feel free to read through each of the other guides in the menu.
Finally, take a look at the options menu (at the bottom left), and see if you can figure out what each of the settings does. Take particular note of the "connect result nodes" checkbox - we will come back to this later.
Neo4j provides a few nice demo graphs to play around with and familiarise yourself with graph databases. You can start by trying the Movies demo, which is a database containing actors and directors.
In the query box, type the following:
:play movies
and press ctrl+enter (or click the blue arrow on the right). You'll be greeted with the following:
If you can't connect to Neo4j, go to DBMSs and start the Movie DBMS. Then click on Open. A new neo4j browser window will be created, and then you can view the Movies demo.
In the query box, type the following:
:play movies
Navigate through the Movies demo using the arrows at the bottom. You can run the query displayed in the grey box by clicking on it (which automatically places it into the query box), then running it via ctrl+enter or clicking the blue arrow*.
After you run the query you might like to try navigating around the graph using the mouse. Have a go at expanding/minimising nodes and moving nodes around.
See if you can figure out how to change the colour of the nodes and the width of the relationships. You can also try changing the text displayed on the node - for example, changing the Person nodes to display birth years instead of names.
Now see if you can find all of the movies Tom Hanks starred in just by looking at the graph. Do you think this graph shows all movies and actors in the database? Why/why not?
Now run each of the queries on the remaining pages. We won't go into detail on how the Cypher queries work just yet, so just try to focus on understanding whether the queries work as you'd expect based on the descriptions of the queries in the demo.
Finally, let's run a simple query of our own:
This query will show every single node in the graph. You should see that the nodes are connected, even though we haven't queried for relationships at all. Now, try going into the options menu (on the bottom left), and deselecting the Connect result nodes button. Run the query again - what happens?
*Note that if you accidentally run the CREATE statements twice, you'll end up with duplicate nodes/edges. I'd recommend deleting the entire graph and starting over. You can do this by running this query:
This will delete all nodes and edges from the graph.
The last exercise for this week is to familiarise yourself with the Arrow Tool, a simple web application for designing graph database schemas.
Your task for this week is to create a simple Movies-based graph that captures the following information:
Robert De Niro acted in the movies "Casino", and "Goodfellas".
Joe Pesci acted in the movies "Goodfellas", "Casino" and "Home Alone".
McCaulay Culkin acted in the movie "Home Alone".
See if you can create this simple graph using the Arrow Tool. Make sure that your "captions" are the node labels (i.e. "Movie" and "Person") and that your properties are the names or titles, for example:
name: Joe Pesci
The relationships should have the caption "ACTED_IN".
Then, click the "Export Cypher" button and paste this into your Neo4j browser. Make sure you have deleted your old movies database first (with the detach delete query above, which is also on page 7 of the demo).
Now run the MATCH (n) RETURN (n)
query again (make sure Connect Result Nodes is enabled in the options). You should see something like the following:
You can change the colour for nodes in neo4j.
For example, there are 4 colours for 4 different node types. If you want to change the colour for Column nodes, just need to click on "Column (11)" and then select a colour you prefer. The size and caption of a node also can be changed in this way.
Head over to and set up a free account.
You can access the Arrow Tool via .