apoc.node.relationship.exists
Function
apoc.node.relationship.exists(node Node, relTypes String)
- returns a boolean based on whether the given node has a relationship (or whether the given node has a relationship of the given type and direction).
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 |
MATCH (p1:Person {name: "Michael"})
RETURN apoc.node.relationship.exists(p1) AS output;
output |
---|
TRUE |
MATCH (p1:Person {name: "Person40"})
RETURN apoc.node.relationship.exists(p1, "FOLLOWS>") AS output;
output |
---|
FALSE |
MATCH (p1:Person {name: "Person40"})
RETURN apoc.node.relationship.exists(p1, "<FOLLOWS") AS output;
output |
---|
TRUE |
Was this page helpful?