Difference between revisions of "Neo4j"

From John Freier
Jump to: navigation, search
(Created page with " == Sample Cypher == Create Node CREATE (n:Label {property:'value'}) return n; Find Node By Id MATCH (n:Label) WHERE Id(n) = 0 RETURN n; Delete Node by Id MATCH (n:No...")
 
Line 10: Line 10:
 
Delete Node by Id
 
Delete Node by Id
 
   MATCH (n:Node) WHERE Id(n) = 0 DELETE n;
 
   MATCH (n:Node) WHERE Id(n) = 0 DELETE n;
 +
 +
Delete All Nodes and Relationships
 +
pre 2.3.0
 +
  MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;
 +
 +
2.3.0 +
 +
  MATCH (n) DETACH DELETE n
 +
 +
Update Nodes properties
 +
  MATCH (n { name: 'John' }) SET n.surname = 'Doe' RETURN n
 +
 +
Create a Relationship
 +
  MATCH (n1:Node), (n2:Node) CREATE (n1)-[r:RELATIONSHIP]->(n2);

Revision as of 11:02, 17 December 2015

Sample Cypher

Create Node

 CREATE (n:Label {property:'value'}) return n;

Find Node By Id

 MATCH (n:Label) WHERE Id(n) = 0 RETURN n;

Delete Node by Id

 MATCH (n:Node) WHERE Id(n) = 0 DELETE n;

Delete All Nodes and Relationships pre 2.3.0

 MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;

2.3.0 +

 MATCH (n) DETACH DELETE n

Update Nodes properties

 MATCH (n { name: 'John' }) SET n.surname = 'Doe' RETURN n

Create a Relationship

 MATCH (n1:Node), (n2:Node) CREATE (n1)-[r:RELATIONSHIP]->(n2);