apoc.node.relationships.exist

Details

Syntax

apoc.node.relationships.exist(node [, relTypes ])

Description

Returns a BOOLEAN based on whether the given NODE has connecting RELATIONSHIP values (or whether the given NODE has connecting RELATIONSHIP values of the given type and direction).

Arguments

Name

Type

Description

node

NODE

The node to check for the specified relationship types.

relTypes

STRING

The relationship types to check for on the given node. Relationship types are represented using APOC’s rel-direction-pattern syntax; [<]RELATIONSHIP_TYPE1[>]|[<]RELATIONSHIP_TYPE2[>]|…​. The default is: `.

Returns

MAP

Usage Examples

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

MERGE (michael:Person {name: "Michael"})
WITH michael
CALL {
    WITH michael
    UNWIND range(0, 100) AS id
    MERGE (p:Person {name: "Person" + id})
    MERGE (michael)-[:KNOWS]-(p)
    RETURN count(*) AS friends
}

CALL {
    WITH michael
    UNWIND range(0, 50) AS id
    MERGE (p:Person {name: "Person" + id})
    MERGE (michael)-[:FOLLOWS]-(p)
    RETURN count(*) AS follows
}

RETURN friends, follows;
Results
friends follows

101

51

MATCH (p1:Person {name: "Person60"})
RETURN apoc.node.relationships.exist(p1, "KNOWS|FOLLOWS") AS output;
Results
output

{KNOWS: TRUE, FOLLOWS: FALSE}

MATCH (p1:Person {name: "Michael"})
RETURN apoc.node.relationships.exist(p1, "KNOWS>|<FOLLOWS") AS output;
Results
output

{KNOWS>: TRUE, <FOLLOWS: FALSE}