An example shell session
# Create a node
neo4j-sh (?)$ mknode --cd
# where are we?
neo4j-sh (0)$ pwd
Current is (0)
(0)
# On the current node, set the key "name" to value "Jon"
neo4j-sh (0)$ set name "Jon"
# send a cypher query
neo4j-sh (Jon,0)$ match (n) where id(n) = 0 return n;
+---------------------+
| n |
+---------------------+
| Node[0]{name:"Jon"} |
+---------------------+
1 row
235 ms
# make an incoming relationship of type LIKES, create the end node with the node properties specified.
neo4j-sh (Jon,0)$ mkrel -c -d i -t LIKES --np "{'app':'foobar'}"
# where are we?
neo4j-sh (Jon,0)$ ls
*name =[Jon]
(me)<-[:LIKES]-(1)
# change to the newly created node
neo4j-sh (Jon,0)$ cd 1
# list relationships, including relationship id
neo4j-sh (1)$ ls -avr
(me)-[:LIKES,0]->(Jon,0)
# create one more KNOWS relationship and the end node
neo4j-sh (1)$ mkrel -c -d i -t KNOWS --np "{'name':'Bob'}"
# print current history stack
neo4j-sh (1)$ pwd
Current is (1)
(Jon,0)-->(1)
# verbose list relationships
neo4j-sh (1)$ ls -avr
(me)-[:LIKES,0]->(Jon,0)
(me)<-[:KNOWS,1]-(Bob,2)
A Matrix example
This example is creating a graph of the characters in the Matrix via the shell and then executing Cypher queries against it:
The following is a sample shell session creating the Matrix graph and querying it.
# Create a reference node neo4j-sh (?)$ mknode --cd # create the Thomas Andersson node neo4j-sh (0)$ mkrel -t ROOT -c -v Node (1) created Relationship [:ROOT,0] created # go to the new node neo4j-sh (0)$ cd 1 # set the name property neo4j-sh (1)$ set name "Thomas Andersson" # create Thomas direct friends neo4j-sh (Thomas Andersson,1)$ mkrel -t KNOWS -cv Node (2) created Relationship [:KNOWS,1] created # go to the new node neo4j-sh (Thomas Andersson,1)$ cd 2 # set the name property neo4j-sh (2)$ set name "Trinity" # go back in the history stack neo4j-sh (Trinity,2)$ cd .. # create Thomas direct friends neo4j-sh (Thomas Andersson,1)$ mkrel -t KNOWS -cv Node (3) created Relationship [:KNOWS,2] created # go to the new node neo4j-sh (Thomas Andersson,1)$ cd 3 # set the name property neo4j-sh (3)$ set name "Morpheus" # create relationship to Trinity neo4j-sh (Morpheus,3)$ mkrel -t KNOWS 2 # list the relationships of node 3 neo4j-sh (Morpheus,3)$ ls -rv (me)-[:KNOWS,3]->(Trinity,2) (me)<-[:KNOWS,2]-(Thomas Andersson,1) # change the current position to relationship #2 neo4j-sh (Morpheus,3)$ cd -r 2 # set the age property on the relationship neo4j-sh [:KNOWS,2]$ set -t int age 3 # back to Morpheus neo4j-sh [:KNOWS,2]$ cd .. # next relationship neo4j-sh (Morpheus,3)$ cd -r 3 # set the age property on the relationship neo4j-sh [:KNOWS,3]$ set -t int age 90 # position to the start node of the current relationship neo4j-sh [:KNOWS,3]$ cd start # new node neo4j-sh (Morpheus,3)$ mkrel -t KNOWS -c # list relationships on the current node neo4j-sh (Morpheus,3)$ ls -r (me)-[:KNOWS]->(4) (me)-[:KNOWS]->(Trinity,2) (me)<-[:KNOWS]-(Thomas Andersson,1) # go to Cypher neo4j-sh (Morpheus,3)$ cd 4 # set the name neo4j-sh (4)$ set name Cypher # create new node from Cypher neo4j-sh (Cypher,4)$ mkrel -ct KNOWS # list relationships neo4j-sh (Cypher,4)$ ls -r (me)-[:KNOWS]->(5) (me)<-[:KNOWS]-(Morpheus,3) # go to the Agent Smith node neo4j-sh (Cypher,4)$ cd 5 # set the name neo4j-sh (5)$ set name "Agent Smith" # outgoing relationship and new node neo4j-sh (Agent Smith,5)$ mkrel -cvt CODED_BY Node (6) created Relationship [:CODED_BY,6] created # go there neo4j-sh (Agent Smith,5)$ cd 6 # set the name neo4j-sh (6)$ set name "The Architect" # go to the first node in the history stack neo4j-sh (The Architect,6)$ cd # Morpheus' friends, looking up Morpheus by name in the Neo4j autoindex neo4j-sh (?)$ start morpheus = node:node_auto_index(name='Morpheus') match (morpheus)-[:KNOWS]-(zionist) return zionist.name; +--------------------+ | zionist.name | +--------------------+ | "Cypher" | | "Trinity" | | "Thomas Andersson" | +--------------------+ 3 rows 110 ms