Course contentsShow
← Computer Science
Lesson 1750 of 2,87239. NoSQL and Modern DatabasesFree lesson

Cypher Query Language Basics

Introduction to Cypher pattern matching syntax for querying graph databases, using ASCII-art patterns.

Cypher Query Language Basics

What You'll Learn

You'll learn how Cypher uses intuitive ASCII-art patterns to query graph databases by visually representing nodes and relationships.

The Visual Language of Graphs

Cypher is the query language for graph databases (like Neo4j), and its genius lies in pattern matching: you literally draw what you're looking for using text. Instead of writing complex JOIN statements like in SQL, you sketch the graph pattern you want to find.

Think of it like giving directions: "I want to find a person who knows another person who lives in Boston." In Cypher, you'd write that almost exactly as you'd draw it on a whiteboard.

ASCII-Art Syntax

Nodes are represented with parentheses: (node)

Relationships use arrows and dashes: --> for directed, -- for undirected

Patterns combine them: (a)-->(b) means "node a connected to node b"

Here's what basic patterns look like:

  • (person) — any node (we call it "person")
  • (person:User) — a node with label "User"
  • (person {name: "Alice"}) — a node with a specific property
  • (a)-->(b) — node a pointing to node b
  • (a)-[:KNOWS]->(b) — node a connected to b via a "KNOWS" relationship

The query structure typically uses MATCH to find patterns:

MATCH (alice)-[:KNOWS]->(friend)

This reads naturally: "Match Alice connected by KNOWS relationship to friend" — finding everyone Alice knows.

The visual nature makes complex graph traversals intuitive. Want friends-of-friends? Just extend the pattern: (alice)-[:KNOWS]->()-[:KNOWS]->(friendOfFriend)

Key Takeaway: Cypher uses ASCII-art pattern matching with parentheses for nodes and arrows for relationships, making graph queries as intuitive as drawing on a whiteboard.