apoc.coll.contains

This function is deprecated. Use Cypher’s IN predicate instead.

Details

Syntax

apoc.coll.contains(coll, value)

Description

Returns whether or not the given value exists in the given collection.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to search for the given value.

value

ANY

The value in the list to check for the existence of.

Returns

BOOLEAN

Usage examples

The following checks if a collection contains a value using APOC and Cypher:

apoc.coll.contains
RETURN apoc.coll.contains([1,2,3,4,5], 4) AS output;
Cypher’s IN keyword
RETURN 4 IN [1,2,3,4,5] AS output;
Results
Output

true

The following checks if a collection contains all the values from another collection:

apoc.coll.contains
RETURN apoc.coll.contains([1,2,3,4,5], [3,7]) AS output;
Cypher’s IN keyword
RETURN [3,7] IN [1,2,3,4,5] AS output;
Results
Output

false

APOC will always return false when matching on a null value:

apoc.coll.contains
RETURN apoc.coll.contains([1, 2, null], null) AS output;
Results
Output

false

To check if a collection contains a null value, it is recommended to use Cypher’s any() function.

Cypher’s any()
RETURN any(x IN [1, 2, null] WHERE x IS NULL) AS output
Results
Output

true