Difference between revisions of "Neo4j"

From John Freier
Jump to: navigation, search
Line 12: Line 12:
 
Create Node
 
Create Node
 
   CREATE (n:Label {property:'value'}) return n;
 
   CREATE (n:Label {property:'value'}) return n;
 +
 +
Create a Relationship
 +
  MATCH (n1:Node), (n2:Node) CREATE (n1)-[r:RELATIONSHIP]->(n2);
 +
  CREATE (n1:Node)-[r:RELATIONSHIP]-(n2:Node) return n1, n2;
  
 
Find Node By Id
 
Find Node By Id
Line 28: Line 32:
 
Update Nodes properties
 
Update Nodes properties
 
   MATCH (n { name: 'John' }) SET n.surname = 'Doe' RETURN n
 
   MATCH (n { name: 'John' }) SET n.surname = 'Doe' RETURN n
 
Create a Relationship
 
  MATCH (n1:Node), (n2:Node) CREATE (n1)-[r:RELATIONSHIP]->(n2);
 
 
  
 
== Neo4J Export ==
 
== Neo4J Export ==

Revision as of 12:55, 22 December 2015

Neo4J

Start Up

 bin/neo4j start

as a script

 bin/neo4j $1

Sample Cypher

Create Node

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

Create a Relationship

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

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

Neo4J Export

Export database as Cypher

 bin/neo4j-shell -c dump > ./filename.cypher

Import database as Cypher

 bin/neo4j-shell -file ./filename.cypher

Execute database statement

 bin/neo4j-shell -c "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;"