One of the things that I’ve found difficult when looking at a new Neo4j database is working out the structure of the data it contains.
I’m used to relational databases where you can easily get a list of the table and the foreign keys that allow you to join them to each other.
This has traditionally been difficult when using Neo4j but with the release of the Neo4j browser we can now easily get this type of overview by clicking on the Neo4j icon at the top left of the browser.
We’ll see something similar to the image on the left which shows the structure of my football graph and we can now discover parts of the graph by clicking on the various labels, properties or relationships.
For example, if we click on the Month label the following query will be executed:
That query actually returns all the months in the database since there are only 12 in total, but for other queries we’d get back a subset of the nodes/relationships with that structure.
To explore the structure around the months we might explore which relationships it has by running a query like this:
From running this query we learn that there is a in_month relationship connecting matches to the month that they were played in.
Another useful exploration mechanism is the allShortestPaths function which will show us the path between two nodes if one exists. For example the following query would show us the path between Wayne Rooney and March:
The text is a bit small but the relationship between Rooney and a match is named played_in so if we want to find which matches Rooney played in in March we could easily write that query.
Another neat feature of the browser is that we can save our queries as we go by clicking on the save button and optionally naming the query in a comment:
We can then access those queries and re-run them if we want via the star tab on the left hand side: