Querying a graph with Cypher
Cypher, Neo4j's language: patterns, relationship direction, variable-length paths, aggregates, CREATE and MERGE.
- 24 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- Scenarios
A few cards from the deck
Pattern: what is it?
Show the answer
An ASCII description of a shape to find in the graph: nodes in parentheses linked by relationships in square brackets and arrows.
(a:Personne)-[:AMI]->(b)reads “a person a and a node b such that a has an AMI relationship to b”; the arrow's direction matters.The graph holds directed AMI relationships: Léa→Tom, Léa→Inès, Léa→Paul, Tom→Zoé, Inès→Zoé, Zoé→Léa. What does
MATCH (p)-[:AMI]->(:Personne {nom:'Léa'}) RETURN count(p)count?- 1
- 3
- 4
- 6
Show the answer
1
The arrow ends at Léa: it counts those who name her as a friend. Only Zoé does. The three friends Léa names would be counted by reversing the arrow.
In Cypher, the … clause filters a pattern's occurrences, and the … clause chooses the result's columns.
Show the answer
In Cypher, the WHERE clause filters a pattern's occurrences, and the RETURN clause chooses the result's columns.
MATCH (p:Personne) WHERE p.age > 30 RETURN p.nomchains the three clauses in that order.MATCH … RETURN: what is it?
Show the answer
The two clauses of a read: the first finds every occurrence of a pattern, the second chooses what is returned for each.
Each occurrence of the pattern gives a row: a node reached by two paths appears twice, unless
RETURN DISTINCT.