apoc.map.mget
Function
apoc.map.mget(map MAP<STRING, ANY>, keys LIST<STRING>, values LIST<ANY>, fail BOOLEAN)
- 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.
Signature
apoc.map.mget(map :: MAP, keys :: LIST<STRING>, values = [] :: LIST<ANY>, fail = true :: BOOLEAN) :: LIST<ANY>
Input parameters
Name | Type | Default |
---|---|---|
map |
MAP |
null |
keys |
LIST<STRING> |
null |
values |
LIST<ANY> |
[] |
fail |
BOOLEAN |
true |
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;
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;
Output |
---|
["Cristiano Ronaldo", "Portugal", "defaultValue"] |