apoc.node.degree

Function APOC Core

apoc.node.degree(node, rel-direction-pattern) - returns total degrees of the given relationships in the pattern, can use '>' or '<' for all outgoing or incoming relationships

Signature

apoc.node.degree(node :: NODE?, types =  :: STRING?) :: (INTEGER?)

Input parameters

Name Type Default

node

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 (p:Person {name: "Michael"})
RETURN apoc.node.degree(p) AS output;
Table 2. Results
output

152

MATCH (p:Person {name: "Michael"})
RETURN apoc.node.degree(p, "FOLLOWS>") AS output;
Table 3. Results
output

51

MATCH (p:Person {name: "Michael"})
RETURN apoc.node.degree(p, "<KNOWS") AS output;
Table 4. Results
output

0