apoc.meta.nodes.count

Function APOC Core

apoc.meta.nodes.count([labels], $config) - Returns the sum of the nodes with a label present in the list.

Signature

apoc.meta.nodes.count(nodes = [] :: LIST? OF STRING?, config = {} :: MAP?) :: (INTEGER?)

Input parameters

Name Type Default

nodes

LIST? OF STRING?

[]

config

MAP?

{}

Config parameters

The procedure support the following config parameters:

Table 1. Config parameters
name type default description

rels

Set<String>

EmptySet

The rel types to consider in the count. We can add to the suffix > or < to the rel type name to indicate an outgoing or incoming relationship.

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (n:MyCountLabel {id: 1}), (:MyCountLabel {id: 2}), (m:ThirdLabel {id: 3})
WITH n,m
CREATE (n)-[:MY_COUNT_REL]->(m), (n)-[:ANOTHER_MY_COUNT_REL]->(m), (n)<-[:ANOTHER_MY_COUNT_REL]-(m)

We can return all nodes with a label MyCountLabel or a label ThirdLabel

RETURN apoc.meta.nodes.count(['MyCountLabel', 'ThirdLabel']) AS count;
Table 2. Results
count relationships

We can return all nodes with a label MyCountLabel and a relationship MY_COUNT_REL through the config param rel

RETURN apoc.meta.nodes.count(['MyCountLabel'], {rels: ['MY_COUNT_REL']}) AS count;
Table 3. Results
count relationships

Moreover, we can return all nodes with a outcome relationship MY_COUNT_REL (with the suffix >):

RETURN apoc.meta.nodes.count(['MyCountLabel'], {rels: ['MY_COUNT_REL>']}) AS count;
Table 4. Results
count relationships

otherwise with an incoming relationship MY_COUNT_REL (with the suffix <):

RETURN apoc.meta.nodes.count(['MyCountLabel'], {rels: ['MY_COUNT_REL<']}) AS count;
Table 5. Results
count relationships