apoc.nodes.relationships.exist

Function APOC Core

apoc.nodes.relationships.exist(node|nodes|id|[ids], rel-direction-pattern) - returns a list of maps where each one has two fields: node which is the node subject of the analysis and exists which is a map with rel-pattern, boolean for the given relationship patterns

Signature

apoc.nodes.relationships.exist(ids :: ANY?, types =  :: STRING?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

ids

ANY?

null

types

STRING?

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;
Table 1. 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;
Table 2. 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}}