Working with Cypher keywords
In this section, we will introduce the Cypher keywords and their syntax. Detailed usage of these keywords will be covered in upcoming sections of the book.
Let us start by using the MATCH
and OPTIONAL
MATCH
keywords.
Using MATCH and OPTIONAL MATCH
The MATCH
keyword allows you to specify the graph traversal patterns to find and return the data from Neo4j. It is most often coupled with a WHERE
clause to filter out the results, and a RETURN
clause to return the results.
- This shows a basic
MATCH
query that will find all nodes in the database and return them. It will also return all the node properties shown as follows:MATCH (n)
RETURN n
- This query finds all the nodes that have the
Movie
label and returns thetitle
property of that node. If there are no nodes with theMovie
label, it does not return any results:MATCH (n:Movie)
RETURN n.title
- This query finds any node that has the
title
property, checks whether its value isMy Movie
, and...