apoc.nodes.relationships.exist

Details

Syntax

apoc.nodes.relationships.exist(nodes [, types ])

Description

Returns a BOOLEAN based on whether or not the given NODE values have the given RELATIONSHIP values.

Arguments

Name

Type

Description

nodes

ANY

Nodes to check for the specified relationship types.

types

STRING

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

Returns

LIST<ANY>

Output parameters

Name Type Description

value

LIST<MAP>

A LIST<MAP> containing MAP values with the keys; "node" → NODE and "exists" → MAP containing STRING values of each type → BOOLEAN indicating its existence.

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)
WHERE p1.name IN ["Michael", "Person30", "Person60"]
WITH collect(p1) AS people
UNWIND apoc.nodes.relationships.exist(people, "KNOWS>|FOLLOWS") AS output
RETURN output;
Results
output

{node: (:Person {name: "Michael"}), exists: {KNOWS>: TRUE, FOLLOWS: TRUE}}

{node: (:Person {name: "Person30"}), exists: {KNOWS>: FALSE, FOLLOWS: TRUE}}

{node: (:Person {name: "Person60"}), exists: {KNOWS>: FALSE, FOLLOWS: FALSE}}