apoc.meta.nodes.countFunction
| This function is restricted on on-premise instances. To use it, it must be unrestricted. For more details, see Installation → Load and unrestrict. |
Syntax |
|
||
Description |
Returns the sum of the |
||
Arguments |
Name |
Type |
Description |
|
|
A list of node labels. The default is: |
|
|
|
A relationship, node or map to get the property types from. { includeRels = [] :: LIST<STRING> } The default is: |
|
Returns |
|
||
Config parameters
This procedure supports the following config parameters:
| Name | Type | Default | Description |
|---|---|---|---|
includeRels |
LIST<STRING> |
[] |
Relationship types to include. Default is to include all relationship types.
Add the suffix |
| Name | Type | Default | Description |
|---|---|---|---|
rels |
LIST<STRING> |
[] |
deprecated, use |
|
This function will count a node as many times as it matches the given labels. To get more accurate results, use Cypher’s Label expressions. |
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})
CREATE (n)-[:MY_COUNT_REL]->(m), (n)-[:ANOTHER_MY_COUNT_REL]->(m), (n)<-[:ANOTHER_MY_COUNT_REL]-(m)
We can return all nodes with the label MyCountLabel or ThirdLabel using both APOC and Cypher:
RETURN apoc.meta.nodes.count(['MyCountLabel', 'ThirdLabel']) AS count
MATCH (n:MyCountLabel|ThirdLabel)
RETURN count(n) AS count
| count |
|---|
3 |
The following example returns all nodes with a label MyCountLabel and a relationship MY_COUNT_REL using both APOC and Cypher:
RETURN apoc.meta.nodes.count(['MyCountLabel'], {includeRels: ['MY_COUNT_REL']}) AS count;
MATCH (n:MyCountLabel)-[:MY_COUNT_REL]-()
RETURN count(n) AS count
| count |
|---|
1 |
The following example returns all nodes with an outgoing relationship MY_COUNT_REL using both APOC and Cypher:
RETURN apoc.meta.nodes.count(['MyCountLabel'], {includeRels: ['MY_COUNT_REL>']}) AS count;
MATCH (n:MyCountLabel)-[:MY_COUNT_REL]->()
RETURN count(n) AS count
| count |
|---|
1 |
The following example returns all nodes with an incoming relationship MY_COUNT_REL using both APOC and Cypher:
RETURN apoc.meta.nodes.count(['MyCountLabel'], {includeRels: ['MY_COUNT_REL<']}) AS count;
MATCH (n:MyCountLabel)<-[:MY_COUNT_REL]-()
RETURN count(n) AS count
| count |
|---|
0 |