Collection & Map Functions

Collection Functions

coll.distinct()

Returns a new list with duplicate values removed, preserving the order of first occurrence.

Syntax: coll.distinct(list)

Parameters:

Parameter Type Description

list

List

The input list

Returns: List - Deduplicated list, or null if input is null

APOC Compatible: apoc.coll.distinct

RETURN coll.distinct([1, 2, 2, 3, 1]) AS result
// Returns: [1, 2, 3]

coll.flatten()

Flattens nested lists into a single list, with configurable depth control.

Syntax: coll.flatten(list [, depth])

Parameters:

Parameter Type Description

list

List

The nested list to flatten

depth

Integer

(Optional) Levels of nesting to flatten. Default: 1. Use -1 for unlimited depth.

Returns: List - Flattened list, or null if input is null

APOC Compatible: apoc.coll.flatten

RETURN coll.flatten([[1, 2], [3, 4]]) AS result
// Returns: [1, 2, 3, 4]

RETURN coll.flatten([[1, [2, 3]], [4]], -1) AS result
// Returns: [1, 2, 3, 4]

RETURN coll.flatten([[1, [2, 3]], [4]], 1) AS result
// Returns: [1, [2, 3], 4]

coll.indexOf()

Returns the index of the first occurrence of a value in a list, or -1 if not found.

Syntax: coll.indexOf(list, value)

Parameters:

Parameter Type Description

list

List

The list to search

value

Any

The value to find

Returns: Integer - Zero-based index, -1 if not found, null if list or value is null

APOC Compatible: apoc.coll.indexOf

RETURN coll.indexOf(["a", "b", "c"], "b") AS result
// Returns: 1

RETURN coll.indexOf([1, 2, 3], 5) AS result
// Returns: -1

coll.insert()

Returns a new list with a value inserted at the given index.

Syntax: coll.insert(list, index, value)

Parameters:

Parameter Type Description

list

List

The original list

index

Integer

Position to insert at (0-based)

value

Any

Value to insert

Returns: List - New list with value inserted, or null if input is null

APOC Compatible: apoc.coll.insert

RETURN coll.insert([1, 2, 3], 1, 99) AS result
// Returns: [1, 99, 2, 3]

coll.max()

Returns the maximum value in a list using Cypher comparison semantics.

Syntax: coll.max(list)

Parameters:

Parameter Type Description

list

List

The input list

Returns: Any - Maximum value, or null if list is null or empty

APOC Compatible: apoc.coll.max

RETURN coll.max([3, 1, 4, 1, 5]) AS result
// Returns: 5

coll.min()

Returns the minimum value in a list using Cypher comparison semantics.

Syntax: coll.min(list)

Parameters:

Parameter Type Description

list

List

The input list

Returns: Any - Minimum value, or null if list is null or empty

APOC Compatible: apoc.coll.min

RETURN coll.min([3, 1, 4, 1, 5]) AS result
// Returns: 1

coll.remove()

Returns a new list with element(s) removed starting at the given index.

Syntax: coll.remove(list, index [, count])

Parameters:

Parameter Type Description

list

List

The original list

index

Integer

Starting position (0-based)

count

Integer

(Optional) Number of elements to remove. Default: 1

Returns: List - New list with elements removed, or null if input is null

APOC Compatible: apoc.coll.remove

RETURN coll.remove([1, 2, 3, 4, 5], 1) AS result
// Returns: [1, 3, 4, 5]

RETURN coll.remove([1, 2, 3, 4, 5], 1, 2) AS result
// Returns: [1, 4, 5]

coll.sort()

Returns a sorted copy of the list using Cypher comparison semantics.

Syntax: coll.sort(list)

Parameters:

Parameter Type Description

list

List

The input list

Returns: List - Sorted list, or null if input is null

APOC Compatible: apoc.coll.sort

RETURN coll.sort([3, 1, 4, 1, 5]) AS result
// Returns: [1, 1, 3, 4, 5]

Map Functions

map.clean()

Remove null values and empty strings from a map.

Syntax: map.clean(map, [keys], [values])

Returns: Map - Cleaned map

APOC Compatible: apoc.map.clean


map.flatten()

Flatten a nested map using a delimiter.

Syntax: map.flatten(map, delimiter)

Returns: Map - Flattened map

APOC Compatible: apoc.map.flatten

RETURN map.flatten({a: {b: 1, c: 2}}, ".") AS result
// Returns: {"a.b": 1, "a.c": 2}

map.fromLists()

Create a map from a list of keys and a list of values.

Syntax: map.fromLists(keys, values)

Returns: Map - New map

APOC Compatible: apoc.map.fromLists

RETURN map.fromLists(["a", "b", "c"], [1, 2, 3]) AS result
// Returns: {a: 1, b: 2, c: 3}

map.fromPairs()

Create a map from a list of key-value pairs.

Syntax: map.fromPairs(pairs)

Returns: Map - New map

APOC Compatible: apoc.map.fromPairs


map.groupBy()

Group a list of maps by a key.

Syntax: map.groupBy(list, key)

Returns: Map - Map of groups

APOC Compatible: apoc.map.groupBy

RETURN map.groupBy([{type: "A", val: 1}, {type: "B", val: 2}, {type: "A", val: 3}], "type") AS result
// Returns: {A: [{type: "A", val: 1}, {type: "A", val: 3}], B: [{type: "B", val: 2}]}

map.merge()

Merge two maps, with the second map’s values overriding the first.

Syntax: map.merge(map1, map2)

Returns: Map - Merged map

APOC Compatible: apoc.map.merge

RETURN map.merge({a: 1, b: 2}, {b: 3, c: 4}) AS result
// Returns: {a: 1, b: 3, c: 4}

map.mergeList()

Merge a list of maps.

Syntax: map.mergeList(listOfMaps)

Returns: Map - Merged map

APOC Compatible: apoc.map.mergeList


map.removeKey()

Remove a key from a map.

Syntax: map.removeKey(map, key)

Returns: Map - Map with key removed

APOC Compatible: apoc.map.removeKey


map.removeKeys()

Remove multiple keys from a map.

Syntax: map.removeKeys(map, keys)

Returns: Map - Map with keys removed

APOC Compatible: apoc.map.removeKeys


map.setKey()

Add or update a key in a map.

Syntax: map.setKey(map, key, value)

Returns: Map - Map with key added/updated

APOC Compatible: apoc.map.setKey

RETURN map.setKey({a: 1}, "b", 2) AS result
// Returns: {a: 1, b: 2}

map.sortedProperties()

Get map entries sorted by key.

Syntax: map.sortedProperties(map)

Returns: List - Sorted list of [key, value] pairs

APOC Compatible: apoc.map.sortedProperties


map.submap()

Extract a subset of keys from a map.

Syntax: map.submap(map, keys, [defaults])

Returns: Map - Submap with specified keys

APOC Compatible: apoc.map.submap


map.unflatten()

Unflatten a map with delimited keys into a nested map.

Syntax: map.unflatten(map, delimiter)

Returns: Map - Nested map

APOC Compatible: apoc.map.unflatten


map.values()

Get all values from a map.

Syntax: map.values(map, [keys])

Returns: List - List of values

APOC Compatible: apoc.map.values