Database Reference
In-Depth Information
Working with the MATCH clause
MATCH is the most important clause used to fetch data from the database. It accepts a pat-
tern, which defines "What to search?" and "From where to search?". If the latter is not
provided, then Cypher will scan the whole tree and use indexes (if defined) in order to
make searching faster and performance more efficient.
Working with nodes
Let's start asking questions from our movie dataset and then form Cypher queries, execute
them on <$NEO4J_HOME>/bin / neo4j-shell against the movie dataset and get the
results that will produce answers to our questions:
• How do we get all nodes and their properties?
Answer : MATCH (n) RETURN n;
Explanation : We are instructing Cypher to scan the complete database
and capture all nodes in a variable n and then return the results, which in
our case will be printed on our Neo4j shell.
• How do we get nodes with specific properties or labels?
Answer : Match with label, MATCH (n:Artist) RETURN n; or
MATCH (n:Movies) RETURN n;
Explanation : We are instructing Cypher to scan the complete database
and capture all nodes, which contain the value of label as Artist or
Movies .
Answer : Match with a specific property MATCH (n:Artist
{WorkedAs:["Actor"]}) RETURN n;
Explanation : We are instructing Cypher to scan the complete database
and capture all nodes that contain the value of label as Artist and the
value of property WorkedAs is [" Actor "]. Since we have defined the
WorkedAs collection, we need to use square brackets, but in all other
cases, we should not use square brackets.
Note
We can also return specific columns (similar to SQL). For example, the preceding state-
ment can also be formed as MATCH (n:Artist {WorkedAs:["Actor"]})
RETURN n.name as Name; .
Search WWH ::




Custom Search