apoc.map.groupBy

Function

apoc.map.groupBy(values LIST<ANY>, key STRING) - creates a MAP of the LIST<ANY> keyed by the given property, with single values.

Signature

apoc.map.groupBy(values :: LIST<ANY>, key :: STRING) :: MAP

Input parameters

Name Type Default

values

LIST<ANY>

null

key

STRING

null

Usage Examples

The following creates a map keyed by club, with a single value

RETURN apoc.map.groupBy([
	{name: "Cristiano Ronaldo", club: "Juventus"},
    {name: "Lionel Messi", club: "Barcelona"},
    {name: "Aaron Ramsey", club: "Juventus"},
    {name: "Luiz Suarez", club: "Barcelona"}
], "club") AS output;
Table 1. Results
Output
{
  "Juventus": {
    "name": "Aaron Ramsey",
    "club": "Juventus"
  },
  "Barcelona": {
    "name": "Luiz Suarez",
    "club": "Barcelona"
  }
}