apoc.nodes.connected
Syntax |
|
||
Description |
Returns true when a given |
||
Arguments |
Name |
Type |
Description |
|
|
The node to check if it is directly connected to the second node. |
|
|
|
The node to check if it is directly connected to the first node. |
|
|
|
If not empty, provides an allow list of relationship types the nodes can be connected by. Relationship types are represented using APOC’s rel-direction-pattern syntax; |
|
Returns |
|
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;
friends | follows |
---|---|
101 |
51 |
apoc.nodes.connected
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2) AS output;
Using Cypher’s EXISTS subquery
RETURN EXISTS { (p1:Person {name: "Michael"})--(p2:Person {name: "Person60"}) } AS output
output |
---|
true |
apoc.nodes.connected
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS") AS output
Using Cypher’s EXISTS subquery
RETURN EXISTS { (p1:Person {name: "Michael"})-[:FOLLOWS]-(p2:Person {name: "Person60"}) } AS output
output |
---|
false |
apoc.nodes.connected
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS>|KNOWS") AS output
Using Cypher’s EXISTS subquery
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person60"})
RETURN EXISTS { (p1)-[:FOLLOWS]->(p2) } OR EXISTS { (p1)-[:KNOWS]-(p2) } AS output
output |
---|
true |
apoc.nodes.connected
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person30"})
RETURN apoc.nodes.connected(p1, p2, "FOLLOWS>") AS output
Using Cypher’s EXISTS subquery
MATCH (p1:Person {name: "Michael"})
MATCH (p2:Person {name: "Person30"})
RETURN EXISTS { (p1)-[:FOLLOWS]->(p2) } AS output
output |
---|
true |