apoc.coll.occurrences

Details

Syntax

apoc.coll.occurrences(coll, item)

Description

Returns the count of the given item in the collection.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to collect the count of the given value from.

item

ANY

The value to count in the given list.

Returns

INTEGER

Usage examples

The following examples return the number of occurrences of the value 9 in a list using both APOC and Cypher:

apoc.coll.occurrences
WITH [1,3,5,7,9,9] AS list, 9 AS match
RETURN apoc.coll.occurrences(list, match) AS output
Using Cypher’s reduce()
WITH [1,3,5,7,9,9] AS list, 9 AS match
RETURN reduce(count = 0, x IN list | count + CASE WHEN x = match THEN 1 ELSE 0 END) AS output
Results
Output

2