Databases : understand how to organize and to use data

Graph-Oriented Databases : Introduction with Neo4J

Graph-oriented databases : Understanding


Modeling Graph databases


Neo4j Graph Visualization Created using Neo4j (http://www.neo4j.com/) ACTED_IN ACTED_IN ACTED_IN Tom Cruise Jerry Maguire Top Gun A Few Good Men

Modeling Graph databases(2)


{
  "identity": 18,
  "labels": [
    "Person"
  ],
  "properties": {
    "name": "Tom Cruise",
    "born": 1962
  }
}
{
  "identity": 49,
  "start": 18,
  "end": 39,
  "type": "ACTED_IN",
  "properties": {
    "roles": [
          "Jerry Maguire"
        ]
  }}

Setting up Neo4j with docker-compose


version: '3.5'
services:
    # ...
    neo4j:
      image: neo4j:4.1
      restart: unless-stopped
      ports:
        - 10474:7474
        - 10687:7687
      volumes:
        - ./neo4j/conf:/conf
        - ./neo4j/data:/data
        - ./neo4j/import:/import
        - ./neo4j/logs:/logs
        - ./neo4j/plugins:/plugins
      environment:
        - NEO4J_dbms_memory_pagecache_size=1G
        - NEO4J_dbms.memory.heap.initial_size=1G
        - NEO4J_dbms_memory_heap_max__size=1G

Setting up Neo4j with docker-compose (2)


firewall-cmd --add-port=10474/tcp --permanent
firewall-cmd --add-port=10687/tcp --permanent
firewall-cmd --reload
docker-compose up -d neo4j
    

open this url in your browser :

http://<your-host>:10474/browser

Using Neo4J + Cypher


On first setup, you will be invited to change the default credentials (neo4j/neo4j)

Graph Queries Queries : Create Node & Relationship


Example: create movie & actor nodes and relationship

CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix)

Graph Queries Queries : Create Node & Relationship


CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})

Graph Queries Queries : Browsing nodes and relationships


Example: search nodes with MATCH & RETURN

MATCH (m:Movie {title:'The Matrix'})
RETURN m

Exercise : complete "The Matrix" Casting

following the previous examples, input the following actors as nodes in the graph, and declare their relationships

declare that they all have acted in "The Matrix" Movie

Larger example : import a movie database


Connecting to neo4j from programming languages