apoc.coll.contains
Syntax |
|
||
Description |
Returns whether or not the given value exists in the given collection. |
||
Arguments |
Name |
Type |
Description |
|
|
The list to search for the given value. |
|
|
|
The value in the list to check for the existence of. |
|
Returns |
|
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;
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;
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;
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
Output |
---|
true |