apoc.map.mget

Details

Syntax

apoc.map.mget(map, keys [, values, fail ])

Description

Returns a LIST<ANY> for the given keys. If one of the keys does not exist, or lacks a default value, this function will throw an exception.

Arguments

Name

Type

Description

map

MAP

The map to extract a list of values from.

keys

LIST<STRING>

The list of keys to extract.

values

LIST<ANY>

The default values of the given keys. The default is: [].

fail

BOOLEAN

If a key is not present and no default is provided, it will either throw an exception if true, or return a null value The default is: true.

Returns

LIST<ANY>

Usage Examples

The following returns a list of values for keys name and country:

WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.mget(map, ["name", "country"]) AS output;
Results
Output

["Cristiano Ronaldo", "Portugal"]

The following returns a list of values for keys name and country, and default value defaultValue for missing key missingKey:

WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.mget(
    map,
    ["name", "country", "missingKey"],
    [null, null, "defaultValue"]
) AS output;
Results
Output

["Cristiano Ronaldo", "Portugal", "defaultValue"]