wmfairuz
5/5/2014 - 6:34 AM

neo4j-cypher-node-crud

neo4j-cypher-node-crud

** CREATE **
// empty node
CREATE (n) RETURN n

// node with properties
CREATE (n {name : 'Fairuz'}) RETURN n 

// add relationship
START a=node(1), b=node(2)
CREATE a-[r:FRIEND_OF]->b
RETURN r

// add relationship with properties
START a=node(1), b=node(2)
CREATE a-[r:BEST_FRIEND_OF {name : a.name + '<->' + b.name }]->b
RETURN r

// create index (use web gui / rest)

// add node to index (not possible. Use java api)


** UPDATE **
START n = node(2)
SET n.name = 'Ali'
RETURN n

** DELETE **
// delete a property
START n = node(2)
SET n.name = null
RETURN n

// delete a node
START n = node(4)
DELETE n

// delete node and relationships
START n = node(3)
MATCH n-[r]-()
DELETE n, r


** REINDEX **
START n=node(*) WHERE HAS(n.name) SET n.name=n.name