Graph databases, Neo4j, Cypher queries, and graph data modeling
When working with highly connected data, social networks, fraud detection, or recommendation engines.
CREATE (alice:Person {name: 'Alice'})-[:FRIEND {since: 2020}]->(bob:Person {name: 'Bob'})
// Match nodes
MATCH (p:Person) WHERE p.name = 'Alice' RETURN p
// Relationships
MATCH (p1:Person)-[:FRIEND]->(p2:Person) RETURN p1, p2
// Pattern matching
MATCH (p:Person)-[:FRIEND]->(friend)-[:FRIEND]->(friendOfFriend)
WHERE p.name = 'Alice'
RETURN friendOfFriend.name
MATCH (p:Person)
WHERE p.age > 25 AND p.name STARTS WITH 'A'
RETURN p
MATCH (p:Person)-[:FRIEND]->(friend)
WITH p, count(friend) AS friendCount
WHERE friendCount > 10
RETURN p
// Shortest path
MATCH path = shortestPath((a:Person)-[*]-(b:Person))
WHERE a.name = 'Alice' AND b.name = 'Charlie'
RETURN path