Introduction to Graphs and Data
Welcome to Neo4j!
Neo4j is a database, a storage for things and their relationships.
It is operated with a language called Cypher.
With it, you can store things, but also find them again.
Let’s try that now. Continue with the arrow to the right.
Save things
We can create ourselves:
MERGE (me:Person {name: 'Jennifer'})
RETURN me
And then we can find ourselves, too:
MATCH (p:Person {name: 'Jennifer'})
RETURN p
We show things as circles: ()
or (:person {name: 'Jennifer'})
Can you find your neighbors? Give it a try!
We can also find all the people:
MATCH (p:Person)
RETURN p
Change things
We can also store more than the name, like birthday or favorite color.
We can find each other and then add new information.
MATCH (p:Person {name: 'Jennifer'})
SET p.birthday = 'May'
SET p.color = 'green'
RETURN p
Now we can see who all likes the color green
.
MATCH (p:Person)
WHERE p.color = 'green'
RETURN p
What if we wanted to find out who doesn’t like the color green? Or who has a birthday in July
?
Connect things
For this, we need two (a pair) of things.
Find you and your neighbor to your right.
MATCH (a:Person {name: 'Jennifer'})
MATCH (b:Person {name: 'Diego'})
RETURN a,b
Relationships are arrows like -->
or -[:KNOWS]->
.
Now we can connect the neighbors.
MATCH (a:Person {name: 'Jennifer'})
MATCH (b:Person {name: 'Diego'})
MERGE (a)-[k:KNOWS]->(b)
RETURN *
How long is our chain? Could we find all the groups of neighbors?
MERGE (a)-[k:KNOWS]->(b)
RETURN *
Is this page helpful?