Neo4j Cheatsheet
Show all nodes
MATCH (n) RETURN n
Delete all nodes
If they have relationships:
MATCH (n) DETACH DELETE n
If they do not have relationships:
MATCH (n) DELETE n
Create a single node, without any relationships
CREATE (:Person {name: "Alice"})
The label of the node is Person, and it has one property: name.
Create two nodes, with a relationship
CREATE (:Person {name: "Alice"}) -[:FALLS_IN]-> (:Place {name:"Rabbit hole"})
This creates two nodes labeled Person and Place, as well as the relationshion FALLS_IN between the nodes.
Create a relationship between two existing nodes
MATCH (alice:Person {name: "Alice"}), (rabbit_hole:Place {name: "Rabbit hole"})
CREATE (alice) -[:FALLS_IN]-> (rabbit_hole)
Update a node property
MATCH (p:Person {name: "Alice"}) SET p.name = "Bob"
This also permits property creation after node creation.
Get all neighbors up to depth X
MATCH (root:Person {name: "Alice"})
MATCH (root)-[*..$depth]-(child)
RETURN DISTINCT root, n
This gives all nodes between 1 and X hops away from root, following any relationship type.