Graph Databases

Table of Contents

What are Graph databases?

Characteristics of graph databases

  • optimized for transactional performance: Native graph processing benefits traversal performance, but at the expense of making some queries that don’t use traversals difficult or memory intensive.
  • advantages: performance, flexibility, agility:
    • performance increase when dealing with connected data
    • schema free: extremely flexible, additive data model
    • mode of delivery aligned with today’s agile software delivery practices

The labeled property graph model

Building blocks of the property graph model (What is a Graph Database?

Example graph: Charlemagne, Einhard and a book

Example graph


  1. The graph shows a node with the label "Person" and the property "Name" on top which has the value "Charlemagne".
  2. Below, to the left, there is another node with the label "Person" by the name of Einhard.
  3. Below, to the right, there is a node with the label "Buch" (book) and the property "Titel" (title) which has the value "Vita Karoli Magni".
  4. The edges indicate through their labels that Charlemagne knew Einhart, that Einhard wrote the book "Vita Karoli Magni" ca. 828-830 and that Charlemagne is mentioned in this book.

Software: Neo4j

  • Download:
  • Or use a Sandbox
  • Start Neo4j-Desktop or use browser interface (http://localhost:7474):
    • At the top left, there is information about the structure of the database and some sample commands. The third tab contains the documentation
    • The input field for the commands is located in the area on the right; below, the window where results are shown
    • First login with neo4j/neo4j. Then assign your own password. Remember the password!
  • Query language: cypher

Practice makes perfect

cypher commands

cypher refcard

My first node

  1. CREATE (n); (creates a node)
  2. CREATE (n) RETURN *; (creates a node and returns it)
  3. CREATE (n:Person) RETURN *; (creates a node with a label and returns the result)
  4. CREATE (n:Person {name:'Andreas'}) RETURN *; (creates a node with a label and an attribute and returns the result)
  5. MERGE (n:Person {name:'Andreas'}) RETURN *; (creates a node with a label and an attribute, if it doesn't exist yet, and returns the result)
  6. MATCH (n:Person {name:'Andreas'}) SET n.placeOfBirth = 'Giessen' RETURN *; (Adds the attribute "placeOfBirth" to a node with the attribute "name:Andreas")

Relation and evaluation

MATCH (n1:Person {name:'Andreas'})
MATCH (n2:Person {name:'Torsten'})
MERGE (n1)-[:KNOWS]->(n2)
RETURN *; (Creates an edge between two nodes, if it doesn't already exist, and returns the nodes and the edge)

MATCH (n:Person)
RETURN n.placeOfBirth, count(*) as count, collect(n.surname) as surname
(names and ranks the places of birth of persons by frequency, order descending)


WS 2018/19 – Summer School Digitale Methodik CC BY-NC-SA 4.0