Neo4j - ID Property



In Neo4j, "Id" is a default internal property for both Nodes and Relationships. That means, when we create a new Node or Relationship, Neo4j Database Server will assign a number for internal usage. It is incremented automatically.

We will go through an example to understand this concept

Example

This example demonstrates how Neo4j DB server assigns an Id Property to a Node and how to view this property value.

Step 1 - Open Neo4j Data Browser

Neo4j CQL Tutorial

Step 2 - Type the below command on Data Browser

CREATE (tweet:Tweet{message:"Hello"})
Neo4j CQL Tutorial

Step 3 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It creates one Node with one Property and one Label.

Step 4 - Type the below command on Data Browser and Click on "Execute" button to observe the results.

MATCH (tweet:Tweet{message:"Hello"})
RETURN tweet
Neo4j CQL Tutorial

Step 5 - Click on "Execute" button to observe the results.

Neo4j CQL Tutorial

Step 6 - Click on circle to view Tweet Node properties

Neo4j CQL Tutorial

If we observe this, we can find an id = 0 property added to this node. When we create another Node, Neo4j DB server will automatically increment this number

Step 7 - Type the below command on Data Browser

CREATE (tweet:Tweet{message:"Hello"})
Neo4j CQL Tutorial

Step 8 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It creates one Node with one Property and one Label.

Step 9 - Type the below command on Data Browser and Click on "Execute" button to observe the results.

MATCH (tweet:Tweet{message:"Hello"})
RETURN tweet

Step 10 - Click on circle to view Tweet Node properties

Neo4j CQL Tutorial

Here we can observe that Node id value is incremented and assigned to one

Note -

In the same way, Neo4j DB server assigns one default Id property to Relationships.

  • Maximum value of Id Property of Node's is around 35 Billion.
  • Maximum value of Id Property of Relationship's is around 35 Billion.
Advertisements