apoc.coll.sortMulti
Function
apoc.coll.sortMulti(coll LIST<MAP<STRING, ANY>>, orderFields LIST<STRING>, limit INTEGER, skip INTEGER)
- sorts the given LIST<MAP<STRING, ANY>>
by the given fields.
To indicate that a field should be sorted according to ascending values, prefix it with a caret (^).
It is also possible to add limits to the LIST<MAP<STRING, ANY>>
and to skip values.
Signature
apoc.coll.sortMulti(coll :: LIST<MAP>, orderFields = [] :: LIST<STRING>, limit = -1 :: INTEGER, skip = 0 :: INTEGER) :: LIST<ANY>
Input parameters
Name | Type | Default |
---|---|---|
coll |
LIST<MAP> |
null |
orderFields |
LIST<STRING> |
[] |
limit |
INTEGER |
-1 |
skip |
INTEGER |
0 |
Usage examples
The following sorts a list of maps by the name
property in ascending order:
RETURN apoc.coll.sortMulti([
{name:'graphs'},
{name:'are',age:32},
{name:'everywhere',age:42}
], ['^name']) as output;
Output |
---|
[{name: "are", age: 32}, {name: "everywhere", age: 42}, {name: "graphs"}] |
The following sorts a list of maps by the name
property in ascending order and then the age
property in descending order:
RETURN apoc.coll.sortMulti([
{name:'graphs'},
{name:'are',age:32},
{name:'are',age:21},
{name:'everywhere'}
], ['^name', 'age']) as output;
Output |
---|
[{name: "are", age: 32}, {name: "are", age: 21}, {name: "everywhere"}, {name: "graphs"}] |
The following sorts a list of maps by the name
property in ascending order and returns only one value:
RETURN apoc.coll.sortMulti([
{name:'graphs'},
{name:'are'},
{name:'everywhere'}
], ['^name'], 1) as output;
Output |
---|
[{name: "are"}] |
The following sorts a list of maps by the name
property in ascending order and skips the first value:
RETURN apoc.coll.sortMulti([
{name:'graphs'},
{name:'are'},
{name:'everywhere'}
], ['^name'], -1, 1) as output;
Output |
---|
[{name: "everywhere"}, {name: "graphs"}] |
The following sorts a list of maps by the name
property in ascending order, skips the first value, and returns only one value:
RETURN apoc.coll.sortMulti([
{name:'graphs'},
{name:'are'},
{name:'everywhere'}
], ['^name'], 1, 1) as output;
Output |
---|
[{name: "everywhere"}] |