Neo4j CQL - REMOVE Label




Neo4j CQL REMOVE clause

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

We use Neo4j CQL SET clause to add new properties to existing Nodes or Relationships.

We use Neo4j CQL REMOVE clause to remove existing properties of Nodes or Relationships.

Neo4j CQL REMOVE command is used

  • To remove labels of a Node or a Relationship

  • To remove properties of a Node or a Relationship

Main Difference between Neo4j CQL DELETE and REMOVE commands:-

  • DELETE operation is used to delete Nodes and associated Relationships.

  • REMOVE operation is used to remove labels and properties.

Similarity between Neo4j CQL DELETE and REMOVE commands:-

  • Both commands should not be used as alone.

  • Both commands should be used with MATCH Command.

We have already discussed how to remove a property or set of properties of a Node or a Relationship in the previous chapter. We will discuss how to remove a label or set of labels of a Node or a Relationship in this chapter.

To Remove a Label of a Node/Relationship

We can use same syntax to remove a Label or list of Labels of a Node or a Relationship permanently from the Database.

REMOVE a Label clause syntax:

REMOVE <label-name-list>
S.No. Syntax Element Description
1. REMOVE It is a Neo4j CQL keyword.
2. <label-name-list> It is a list of labels to remove it from a Node or a Relationship permanently.

<label-name-list> syntax:

<node-name>:<label1-name>,
<node-name>:<label2-name>, 
.... 
<node-name>:<labeln-name> 

Syntax Description

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

NOTE:-

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

  • We should use colon(:) operator to separate the node names and label name.

Example1:-

This example demonstrates how to remove an unwanted label to a Node permanently from the Database.

Steps to follow:

  • Open Neo4j Data Browser

  • Neo4j CQL Tutorial

    It is Neo4j Data Browser Homepage

  • Type the below command on Data Browser

MATCH (m:Movie) RETURN m
Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial
  • Click on node to see its properties window.

  • Neo4j CQL Tutorial

    Here we can observe that four labels are available to a single node.

    As per our client requirement, we need to remove "Picture" label to this node

  • Type below command on Browser and click on Execute button.

  • MATCH (m:Movie) 
    REMOVE m:Picture
    
    Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial

    Here we can observe that one label is removed from node permanently from the Database.

  • Type the below command on Data Browser

  • MATCH (m:Movie) RETURN m
    
    Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial
  • Click on node to see its properties window.

  • Neo4j CQL Tutorial

    Here we can observe that this node has only three labels :Movie,Cinema,Film from Properties Window. That means our previous command has removed Picture label successfully.

    Advertisements