apoc.coll.sortMaps
Syntax |
|
||
Description |
Sorts the given |
||
Arguments |
Name |
Type |
Description |
|
|
The list of maps to be sorted. |
|
|
|
The property key to be used to sort the list of maps by. |
|
Returns |
|
Usage examples
The following examples sort a list of maps in reverse alphabetical order by the key name
using both APOC and Cypher:
WITH [
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
] AS list
RETURN apoc.coll.sortMaps(list, "name") AS output
WITH [
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
] AS list
RETURN COLLECT {
UNWIND list AS x
RETURN x ORDER BY x.name DESC
} AS output
output |
---|
[ { "name": "Wayne Rooney" } , { "name": "Lionel Messi" } , { "name": "Cristiano Ronaldo" } ] |
The following examples sort a list of maps in alphabetical order by the key name
using both APOC and Cypher:
WITH [
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
] AS list
RETURN apoc.coll.sortMaps(list, "^name") AS output
WITH [
{name: "Lionel Messi"},
{name: "Cristiano Ronaldo"},
{name: "Wayne Rooney"}
] AS list
RETURN COLLECT {
UNWIND list AS x
RETURN x ORDER BY x.name
} AS output
output |
---|
[ { "name": "Cristiano Ronaldo" } , { "name": "Lionel Messi" } , { "name": "Wayne Rooney" } ] |