apoc.map.get
Function
apoc.map.get(map MAP<STRING, ANY>, key STRING, value ANY, fail BOOLEAN)
- returns a value for the given key.
If the given key does not exist, or lacks a default value, this function will throw an exception.
Signature
apoc.map.get(map :: MAP, key :: STRING, value = null :: ANY, fail = true :: BOOLEAN) :: ANY
Usage Examples
The following throws an exception when attempting to look up missing key missingKey
with no default value:
WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.get(map, "missingKey") AS output;
Output |
---|
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke function |
The following returns default value defaultValue
when attempting to look up missing key missingKey
:
WITH {name:"Cristiano Ronaldo", country:"Portugal", dob:date("1985-02-05")} AS map
RETURN apoc.map.get(map, "missingKey", "defaultValue") AS output;
Output |
---|
"defaultValue" |