Tiny cheat sheet to remind the funky syntax of Cypher
Semantic | Command |
---|---|
Add with relationship | CREATE (p:Person)-[:LIKES]->(t:Technology) |
Add nodes, then link them | CREATE (friend:Person {name: ‘Mark’}) \n MATCH (jennifer:Person {name: ‘Jennifer’})\n MATCH (mark:Person {name: ‘Mark’}) \nCREATE (jennifer)-[rel:IS_FRIENDS_WITH]->(mark) |
Add with no duplicate | MERGE (mark:Person {name: ‘Mark’}) |
Update node | MATCH (p:Person {name: ‘Jennifer’}) \n SET p.birthdate = date(‘1980-01-01’) |
Update relationship | MATCH (:Person {name: ‘Jennifer’})-[rel:WORKS_FOR]-(:Company {name: ‘Neo4j’}) \n SET rel.startYear = date({year: 2018}) \n RETURN rel |
Delete | MATCH (j:Person {name: ‘Jennifer’})-[r:IS_FRIENDS_WITH]->(m:Person {name: ‘Mark’}) \n DELETE r |
Delete all nodes | MATCH (n) DETACH DELETE n; \n MATCH (n) DELETE n; |
Find (complete) | MATCH (p:Person {name: “Jennifer”})-[rel:LIKES]->(g:Technology {type: “Graphs”}) RETURN p.name AS PersonName |
Sources: