Forked from nawroth/GraphGist-create-nodes-and-rels.adoc
Created
January 20, 2014 01:22
-
-
Save csthompson/8513450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Create nodes and relationships = | |
// console | |
Create a node for the actor Tom Hanks: | |
[source,cypher] | |
---- | |
CREATE (n:Actor {name:"Tom Hanks"}); | |
---- | |
Let's find the node we created: | |
[source,cypher] | |
---- | |
MATCH (actor:Actor) | |
WHERE actor.name = "Tom Hanks" | |
RETURN actor; | |
---- | |
Now let's create a movie and connect it to the Tom Hanks node with an `ACTED_IN` relationship: | |
[source,cypher] | |
---- | |
MATCH (actor:Actor) | |
WHERE actor.name = "Tom Hanks" | |
CREATE (movie:Movie {title:'Sleepless in Seattle'}) | |
CREATE (actor)-[:ACTED_IN]->(movie); | |
---- | |
// This is how our graph looks now: | |
// g r a p h | |
We can do more of the work in a single clause. | |
`CREATE UNIQUE` will make sure we don't create duplicate patterns. | |
Using this: `[r:ACTED_IN]` lets us return the relationship. | |
[source,cypher] | |
---- | |
MATCH (actor:Actor) | |
WHERE actor.name = "Tom Hanks" | |
CREATE UNIQUE (actor)-[r:ACTED_IN]->(movie:Movie {title:"Forrest Gump"}) | |
RETURN r; | |
---- | |
Set a property on a node: | |
[source,cypher] | |
---- | |
MATCH (actor:Actor) | |
WHERE actor.name = "Tom Hanks" | |
SET actor.DoB = 1944 | |
RETURN actor.name, actor.DoB; | |
---- | |
The labels 'Actor' and 'Movie' help us organize the graph. | |
Let's list all 'Movie' nodes: | |
[source,cypher] | |
---- | |
MATCH (movie:Movie) | |
RETURN movie AS `All Movies`; | |
---- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment