Developer Guides Getting Started Getting Started What is a Graph Database? Intro to Graph DBs Video Series Concepts: RDBMS to Graph Concepts: NoSQL to Graph Getting Started Resources Neo4j Graph Platform Graph Platform Overview Neo4j Desktop Intro Neo4j Browser Intro… Read more →
Guide to Cypher Basics
This guide explains the basic concepts of Cypher, Neo4j’s query language, including how to create and query graphs. You should be able to read and understand Cypher queries after finishing this guide.
You should have familiarized yourself with Graph Databases and the Property Graph Model.
Pop-Cultural Connections
The Movie Graph is a mini graph application containing actors and directors that are related through the movies they’ve collaborated on.
It is available in your Neo4j Browser if you execute :play movie-graph
.
It is helpful if you run the queries as you go along, but you should understand them even so.
This guide will show you how to:
- Create: insert movie data into the graph
- Find: retrieve individual movies and actors
- Query: discover related actors and directors
- Solve: the Bacon Path
Create
Hidden below this text is a giant code block containing a single Cypher query statement composed of multiple CREATE
clauses.
This will create the movie graph.
(You can unfold it with the little [role=’icon-plus-sign-alt’]plus button)
Find
Example queries for finding individual nodes.
- Look at every query example
- Run the query with the play button
- Notice the syntax pattern
- Try looking for other movies or actors
Query
Finding patterns within the graph.
- Actors are people who acted in movies
- Directors are people who directed a movie
- What other relationships exist?
List All Tom Hanks Movies…
MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies)
RETURN tom,tomHanksMovies
Solve the Six Degrees Question
You’ve heard of the classic “Six Degrees of Kevin Bacon”? That is simply a shortest path query called the “Bacon Path”.
- Variable length patterns
- Built-in shortestPath() algorithm
Clean Up
When you’re done experimenting, you can remove the movie data set.
- Nodes can’t be deleted if relationships to them exist
- Delete both nodes and relationships together
This will remove all Person and Movie nodes! |