Neo4J Components

Nodes

Labels

Properties

Relationships

Unlike MySQL, you don't create Tables / Schemas first. You start creating the actual Node (Datapoint).

Node

// Create a single Node

create (n)

match(t) return t

create (anything),(seriously_anything)

match(e) return e

Label

// Node with Label

create(n:Student)

match(y) return y

Label every node. Nodes without Labels are not useful.

// To name a Node after Creation. Example ID=2 set Label to Building

match(n) where ID(n)=2 set t:somelabel

// To rename a Label

match(n) where ID(n)=2 set t:Building remove t:somelabel 

match(n) return n

Remember Algebra? we always find x? Why it's always x?

In the same way, in Neo4J, the node is called n.

Properties

create (n:Book{title:"The Sapiens", author:"Yuval Noah"});

create (n:Book{title:"Who Moved My Cheese", author:"Johnson M.D"});

// Set Property for node which doesnt have Property
match(t) where ID(t)=2 set t.name="RobinsonHall" return t

// show all nodes

match(t) return t

Relationships

Create relationships

Create a relationship between the existing nodes

Create a relationship with labels and properties

CREATE (node1)-[:RelationshipType]->(node2)

Last updated