apoc.nodes.connected

Function APOC Core

apoc.nodes.connected(start, end, rel-direction-pattern) - returns true when the node is connected to the other node, optimized for dense nodes

Signature

apoc.nodes.connected(start :: NODE?, start :: NODE?, types =  :: STRING?) :: (BOOLEAN?)

Input parameters

Name Type Default

start

NODE?

null

start

NODE?

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 {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2) AS output;
Table 2. Results
output

TRUE

MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS") AS output;
Table 3. Results
output

FALSE

MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS>|KNOWS") AS output;
Table 4. Results
output

TRUE

MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person30"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS>") AS output;
Table 5. Results
output

TRUE