Skip to content

Instantly share code, notes, and snippets.

@wmfairuz
Created May 5, 2014 06:34
Show Gist options
  • Save wmfairuz/11530011 to your computer and use it in GitHub Desktop.
Save wmfairuz/11530011 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment