apoc.coll.sortMaps

Details

Syntax

apoc.coll.sortMaps(list, prop)

Description

Sorts the given LIST<MAP<STRING, ANY>> into descending order, based on the MAP property indicated by prop.

Arguments

Name

Type

Description

list

LIST<MAP>

The list of maps to be sorted.

prop

STRING

The property key to be used to sort the list of maps by.

Returns

LIST<ANY>

Usage examples

The following sorts a list of maps in reverse alphabetical order by the key name:

RETURN apoc.coll.sortMaps([
    {name: "Lionel Messi"},
    {name: "Cristiano Ronaldo"},
    {name: "Wayne Rooney"}
], "name") AS output;
Results
Output
[
    {
      "name": "Wayne Rooney"
    }
    ,
    {
      "name": "Lionel Messi"
    }
    ,
    {
      "name": "Cristiano Ronaldo"
    }
]

The following sorts a list of maps in alphabetical order by the key name:

RETURN apoc.coll.sortMaps([
    {name: "Lionel Messi"},
    {name: "Cristiano Ronaldo"},
    {name: "Wayne Rooney"}
], "^name") AS output;
Results
Output
[
    {
      "name": "Cristiano Ronaldo"
    }
    ,
    {
      "name": "Lionel Messi"
    }
    ,
    {
      "name": "Wayne Rooney"
    }
]