apoc.label.exists

Details

Syntax

apoc.label.exists(node, label)

Description

Returns true or false depending on whether or not the given label exists.

Arguments

Name

Type

Description

node

ANY

A node to check for the given label on.

label

STRING

The given label to check for existence.

Returns

BOOLEAN

Label Expressions in Cypher

The existence of a label, as well as more complicated expressions, can be determined using Cypher’s label expressions.

Cypher syntax for checking the existence of a label
MATCH (n)
RETURN n:Label

To check for label existence dynamically, the IN keyword can be used alongside the labels() function:

Cypher syntax for checking the existence of a label dynamically
MATCH (n)
RETURN $labelAsAParam IN labels(n)

Usage Examples

The examples in this section are based on the following graph:

CREATE (s1:Student {name: 'Priya'});

The following examples return whether or not the node has the 'Student' label using both APOC and Cypher:

apoc.label.exists
MATCH (s1 {name: 'Priya'})
RETURN apoc.label.exists(s1, "Student") AS output;
Using Cypher’s label expressions
MATCH (s1 {name: 'Priya'})
RETURN s1:Student AS output
Results
output

true

apoc.label.exists
MATCH (s1:Student {name: 'Priya'})
RETURN apoc.label.exists(s1, "Teacher") AS output;
Using Cypher’s label expressions
MATCH (s1 {name: 'Priya'})
RETURN s1:Teacher AS output
Results
output

false