apoc.coll.sortMaps

Function

apoc.coll.sortMaps(list [Map<String, Any>], prop String) - sorts the given list into ascending order, based on the map property indicated by name.

Signature

apoc.coll.sortMaps(coll :: LIST? OF MAP?, prop :: STRING?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

coll

LIST? OF MAP?

null

prop

STRING?

null

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;
Table 1. 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;
Table 2. Results
Output
[
    {
      "name": "Cristiano Ronaldo"
    }
    ,
    {
      "name": "Lionel Messi"
    }
    ,
    {
      "name": "Wayne Rooney"
    }
]