apoc.node.degree

Details

Syntax

apoc.node.degree(node [, relTypes ])

Description

Returns the total degrees of the given NODE.

Arguments

Name

Type

Description

node

NODE

The node to count the total number of relationships on.

relTypes

STRING

The relationship types to restrict the count to. Relationship types are represented using APOC’s rel-direction-pattern syntax; [<]RELATIONSHIP_TYPE1[>]|[<]RELATIONSHIP_TYPE2[>]|…​. The default is: ``.

Returns

INTEGER

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;
Results
friends follows

101

51

apoc.node.degree
MATCH (p:Person {name: "Michael"})
RETURN apoc.node.degree(p) AS output
Using Cypher’s count() and pattern matching
MATCH (p:Person {name: "Michael"})
RETURN COUNT { (p)--() } AS output
Results
output

152

apoc.node.degree
MATCH (p:Person {name: "Michael"})
RETURN apoc.node.degree(p, "FOLLOWS>") AS output
Using Cypher’s count() and pattern matching
MATCH (p:Person {name: "Michael"})
RETURN COUNT { (p)-[:FOLLOWS]->() } AS output
Results
output

51

apoc.node.degree
MATCH (p:Person {name: "Michael"})
RETURN apoc.node.degree(p, "<KNOWS") AS output
Using Cypher’s COUNT subquery and pattern matching
MATCH (p:Person {name: "Michael"})
RETURN COUNT { (p)<-[:KNOWS]-() } AS output
Results
output

0