Blog

  • Neo4j Create Query

    Posted by Vipul Pandey | Last Updated: 28-Sep-17

    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
    
     
     

Tags: neo4j