Neo4j Create Node

In the Neo4j to create node you will have to state CREATE statement. With the help of cypher language it is easy to create nodes, properties and relation between nodes. Let’s create sample node of GeeksforGeesk. You can see the table format, the actual code and the text also by selecting options. Below examples will illustrate the concept more clearly.

Example: In this example we will create a node label “GeeksforGeeks” with the “Tag” property that will tell us about the “GeeksforGeeks” that will be property value.

  • To create the node:
    $ CREATE (a:GeeksforGeeks { Tag : "A Computer Science Portal" })
    

    The prefix a is a variable that will be anything this thing will required to refer later in any statement. After firing the Cypher query you will get something like the below picture.
    Output:

  • Display node:
    So now you have a created node but the above query does not show you the created node to see the node you need to use RETURN statement like have to fire the below query. Here again we will create a node with 2 properties.



  • Display Created node:
    $ CREATE (a:GeksforGeeks { Tag : "A Computer Science Portal", Type : "Edutech" }) 
    RETURN a
    

    Output:

    Note: We return the node by using its variable name (in this case a).

  • Creating multiple nodes:
    To create multiple nodes use the CREATE statement and separate the nodes by “, ” coma or you can use multiple time CREATE statement Like the below query.

  • Multiple nodes single Query using coma:
    $ CREATE (a:GeeksforGeeks { Tag: "A Computer Science Portal"}), 
    (b:W3School { Tag: "We are the Learner"}) 
    RETURN a, b
    

    or

    CREATE (a:GeeksforGeeks { Tag: "A Computer Science Portal"}) 
    CREATE (b:W3School { Tag: "We are the Learner"}) 
    RETURN a, b
    

    Output:

  • Note: Both the query will gave you same output.



    My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.