Skip to content

Instantly share code, notes, and snippets.

@DMeechan
Created June 18, 2019 10:39
Show Gist options
  • Save DMeechan/fb930cb8039688486238e88ef9aa7721 to your computer and use it in GitHub Desktop.
Save DMeechan/fb930cb8039688486238e88ef9aa7721 to your computer and use it in GitHub Desktop.
Handy Neo4j Commands

Handy Neo4j Commands

Learn more on this page in the Neo4j docs.

Created with help from @DaniSancas's Neo4j Cypher cheatsheet.

Finding all nodes

View all nodes

MATCH (n) RETURN N

Delete all nodes (and return how many were deleted)

MATCH (n) DETACH DELETE (n) RETURN COUNT(n)

Finding specific nodes

Find all Resource nodes

MATCH (r: Resource) RETURN r

Find Concept nodes with the title "Object-Oriented Programming"

MATCH (target:Concept {title: "Object-Oriented Programming"}) RETURN target

Finding nodes and their relations

Find Concept nodes with the title "Object-Oriented Programming" AND all of their child nodes

MATCH (target:Concept {title: "Object-Oriented Programming"})-[relations]-(children) RETURN target, relations, children

Recursively find child Concept nodes with a TEACHES relation to the Concept c0

MATCH (this: Concept {id: "c0"})-[:TEACHES *1..]->(c:Concept) return this, c

Find every Module which TEACHES a Lecture, then return those modules and lectures.

MATCH (m: Module)-[:TEACHES]->(lec: Lecture) RETURN m, lec

Find every Module which TEACHES a Lecture... and then find every Concept which is taught by one of those lectures... then return those modules, lectures, and concepts.

MATCH (m: Module)-[:TEACHES]->(lec: Lecture) MATCH(lec)-[:TEACHES]->(c:Concept) RETURN m, lec, c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment