Collection Functions
APOC has a wide variety of Collection and List functions.
|
sum of all values in a list |
|
avg of all values in a list |
|
minimum of all values in a list |
|
maximum of all values in a list |
|
sums all numeric values in a list |
|
partitions a list into sublists of |
|
all values in a list |
|
[1,2],[2,3],[3,null] |
|
[1,2],[2,3] |
|
returns a unique list backed by a set |
|
sort on Collections |
|
sort nodes by property, ascending sorting by adding ^ in front of the sorting field |
|
sort maps by map key, ascending sorting by adding ^ in front of the sorting field |
|
returns the reversed list |
|
returns true if collection contains the value |
|
optimized contains-all operation (using a HashSet) returns true or false |
|
optimized contains on a sorted list operation (Collections.binarySearch) (returns true or false) |
|
optimized contains-all on a sorted list operation (Collections.binarySearch) (returns true or false) |
|
return true if two collections contain the same elements with the same cardinality in any order (using a HashMap) |
|
creates the distinct union of the 2 lists |
|
creates the full union with duplicates of the two lists |
|
returns unique set of first list with all elements of second list removed |
|
returns first list with all elements of second list removed |
|
returns the unique intersection of the two lists |
|
returns the disjunct set of the two lists |
|
splits collection on given values rows of lists, value itself will not be part of resulting lists |
|
position of value in the list |
|
returns the shuffled list |
|
returns a random item from the list |
|
returns a list of |
|
returns true if a collection contains duplicate elements |
|
returns a list of duplicate items in the collection |
|
returns a list of duplicate items in the collection and their count, keyed by |
|
returns the count of the given item in the collection |
|
returns a list of frequencies of the items in the collection, keyed by |
|
return a map of frequencies of the items in the collection, keyed by |
|
sort list of maps by several sort fields (ascending with ^ prefix) and optionally applies limit and skip |
|
flattens a nested list |
|
Returns collection of all combinations of list elements of selection size between minSelect and maxSelect (default:minSelect), inclusive |
|
deconstruct subset of mixed list into identifiers of the correct type |
|
set index to value |
|
insert value at index |
|
insert values at index |
|
remove range of values from index to length |
|
returns true if value are different |
|
returns a list with the given count of items |
|
sort on string based collections |
RETURN apoc.coll.sum([1,2,3,4,5]) AS output
Output |
---|
15.0 |
RETURN apoc.coll.avg([1,2,3,4,5]) AS output
Output |
---|
3.0 |
RETURN apoc.coll.min([1,2,3,4,5]) AS output
Output |
---|
1 |
RETURN apoc.coll.max([1,2,3,4,5]) AS output
Output |
---|
5 |
RETURN apoc.coll.sumLongs([1,2,3,4,5]) AS output
Output |
---|
15 |
2
:CALL apoc.coll.partition([1,2,3,4,5], 2)
Value |
---|
[1, 2] |
[3, 4] |
[5] |
RETURN apoc.coll.zip([1,2,3], ["a", "b", "c"]) as output
Output |
---|
[[1, "a"], [2, "b"], [3, "c"]] |
RETURN apoc.coll.pairs([1,2,3,4,5]) AS output
Output |
---|
[[1, 2], [2, 3], [3, 4], [4, 5], [5, null]] |
RETURN apoc.coll.pairsMin([1,2,3,4,5]) AS output
Output |
---|
[[1, 2], [2, 3], [3, 4], [4, 5]] |
RETURN apoc.coll.toSet([1,1,2,1,3,4,1]) AS output
Output |
---|
[1, 2, 3, 4] |
RETURN apoc.coll.sort([5,4,2,3,1]) AS output
Output |
---|
[1, 2, 3, 4, 5] |
name
:RETURN apoc.coll.sortMaps([
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
], "name") AS output
Output |
---|
|
name
:RETURN apoc.coll.sortMaps([
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
], "name^") AS output
Output |
---|
|
RETURN apoc.coll.reverse([5,4,3,2,1]) AS output
Output |
---|
[1, 2, 3, 4, 5] |
RETURN apoc.coll.contains([1,2,3,4,5], 4) AS output
Output |
---|
true |
RETURN apoc.coll.contains([1,2,3,4,5], [3,7]) AS output
Output |
---|
false |
RETURN apoc.coll.union([1,2,3,4,5], [3,4,5,6,7]) AS output
Output |
---|
[1, 2, 3, 4, 5, 6, 7] |
RETURN apoc.coll.unionAll([1,2,3,4,5], [3,4,5,6,7]) AS output
Output |
---|
[1, 2, 3, 4, 5, 3, 4, 5, 6, 7] |
RETURN apoc.coll.subtract([1,2,3,4,5,6,6], [3,4,5]) AS output
Output |
---|
[1, 2, 6] |
RETURN apoc.coll.subtract([1,2,3,4,5,6,6], [3,4,5]) AS output
Output |
---|
[1, 2] |
RETURN apoc.coll.removeAll([1,2,3,4,5,6,6], [3,4,5]) AS output
Output |
---|
[1, 2, 6, 6] |
RETURN apoc.coll.intersection([1,2,3,4,5], [3,4,5]) AS output
Output |
---|
[3, 4, 5] |
RETURN apoc.coll.disjunction([1,2,3,4,5], [3,4,5]) AS output
Output |
---|
[1, 2] |
.
:CALL apoc.coll.split(["Hello", "World", ".", "How", "are", "you", "?"], ".")
Value |
---|
["Hello", "World"] |
["How", "are", "you", "?"] |
3
in the list:RETURN apoc.coll.indexOf([1,3,5,7,9], 3) AS output
Output |
---|
1 |
RETURN apoc.coll.shuffle([1,3,5,7,9]) AS output
Output |
---|
[7, 5, 9, 3, 1] |
RETURN apoc.coll.randomItem([1,3,5,7,9]) AS output
Output |
---|
7 |
2
random values from a list:RETURN apoc.coll.randomItems([1,3,5,7,9], 2) AS output
Output |
---|
[5, 3] |
RETURN apoc.coll.containsDuplicates([1,3,5,7,9,9]) AS output
Output |
---|
true |
RETURN apoc.coll.duplicates([1,3,5,7,9,9]) AS output
Output |
---|
[9] |
RETURN apoc.coll.duplicatesWithCount([1,3,5,7,9,9]) AS output
Output |
---|
|
9
in a list:RETURN apoc.coll.occurrences([1,3,5,7,9,9], 9) AS output
Output |
---|
2 |
RETURN apoc.coll.frequencies([1,3,5,7,9,9]) AS output
Output |
---|
|
RETURN apoc.coll.frequenciesAsMap([1,3,5,7,9,9]) AS output
Output |
---|
|
RETURN apoc.coll.flatten([1,2,3,[4,5,6]]) AS output
Output |
---|
[1, 2, 3, 4, 5, 6] |
3
and 4
elements:RETURN apoc.coll.combinations([1,3,5,7,9], 3, 4) AS output
Output |
---|
[[1, 3, 5], [1, 3, 7], [1, 5, 7], [3, 5, 7], [1, 3, 9], [1, 5, 9], [3, 5, 9], [1, 7, 9], [3, 7, 9], [5, 7, 9], [1, 3, 5, 7], [1, 3, 5, 9], [1, 3, 7, 9], [1, 5, 7, 9], [3, 5, 7, 9]] |
4
with the value 11
:RETURN apoc.coll.set([1,3,5,7,9], 4, 11) AS output
Output |
---|
[1, 3, 5, 7, 11] |
11
at index 3
in the list:RETURN apoc.coll.insert([1,3,5,7,9], 3, 11) AS output
Output |
---|
[1, 3, 5, 11, 7, 9] |
2
values, starting from index 1
:RETURN apoc.coll.remove([1,3,5,7,9], 1, 2) AS output
Output |
---|
[1, 7, 9] |
RETURN apoc.coll.different([1,3,5,7,9]) AS output
Output |
---|
true |
// n.b. if no locale is provided it takes the default of the machine where neo4j is running on
RETURN apoc.coll.sortText(['Єльська', 'Гусак'], {locale: 'ru'}) as Output
Output |
---|
Гусак |
Єльська |