Neo4j Create Query

Posted By : Vipul Pandey | 28-Sep-2017

The CREATE clause in neo4j is used to create graph elements — nodes and relationships.

create(a:test)  return a ; 

This will create a node in neo4j and default

a id will be assigned to it


create(a:test{name:"vipul"}) return a ;

This will create a node in neo4j and default

a id and the name property will be  set to the node.
We can similarly create multiple properties in the node.

create(add:Address{country:"India",capital:"DELHI"})
return add

creating a relationship between the nodes

match(a:test)
 where a.name="vipul"
match(add:Address)
 where add.Country="India"
create(a)-[rel:LIVES_IN]->(add)
return a,add

we can create multiple relationships between 2 nodes as

match(a:test)
where a.name="vipul"
match(add:Address)
where add.Country="India"
create(a)-[rel:BELONGS_TO]->(add)
return a,rel ,add

We can also set properties to the relation as :

match(a:test)
where a.name="vipul"
match(add:Address)
where add.Country="India"
create(a)-[rel:LIVES_IN{by:"birth"}]->(add)
return a,rel ,add
 
 

About Author

Author Image
Vipul Pandey

Vipul Pandey is a good team-player & developing application on MEAN and java spring boot. Vipul loves to keep rotating fingers in his keyboard until he creates somethings inspiring.Hobbies are playing cricket ,swimming & photography.

Request for Proposal

Name is required

Comment is required

Sending message..