Neo4j CQL - SET



Sometimes, based on our client requirements, we need to add new properties to existing Nodes or Relationships.

To do this, Neo4j CQL has provided a SET clause.

Neo4j CQL has provided SET clause to perform the following.

  • Add new properties to existing Node or Relationship
  • Add or Update Properties values

SET clause syntax

SET  <property-name-list>
S.No.Syntax ElementDescription
1.SETIt is a Neo4j CQL keyword.
2.<property-name-list>It is a list of properties to perform add or update operation to fulfil our requirements.

<property-name-list> syntax:

<node-label-name>.<property1-name>,
<node-label-name>.<property2-name>, 
.... 
<node-label-name>.<propertyn-name> 

Syntax Description

S.No.Syntax ElementDescription
1.<node-label-name>It is a label name of a Node.
2.<property-name>It is a property name of a Node.

NOTE -

We should use comma(,) operator to separate the property names list.

Example

This example demonstrates how to add a new property to existing DebitCard Node.

Step 1 - Open Neo4j Data Browser

Neo4j CQL Tutorial

Step 2 - Type the below command on Data Browser

MATCH (dc:DebitCard)
RETURN dc
Neo4j CQL Tutorial

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

Neo4j CQL Tutorial

Here we can observe that "DebitCard" node has 5 properties. Now we are going to add new property "atm_pin" to this node.

Step 4 - Type the below command on Data Browser

MATCH (dc:DebitCard)
SET dc.atm_pin = 3456
RETURN dc
Neo4j CQL Tutorial

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

Neo4j CQL Tutorial

Here we can observe new property is added to "DebitCard" node.

Advertisements