Creates a new map with a single specified key removed. The original map is not modified.
flex.map.removeKey(map, key)| Parameter | Type | Required | Description |
|---|---|---|---|
map |
map | Yes | The map to remove the key from |
key |
string | Yes | The key to remove |
Type: map (object)
A new map containing all properties from the input map except the specified key. Returns an empty map if input is not a valid object.
WITH {name: 'Alice', age: 30, email: 'alice@example.com'} AS user
RETURN flex.map.removeKey(user, 'email') AS sanitizedOutput:
sanitized
-----------------------
{name: 'Alice', age: 30}
MATCH (u:User)
WITH properties(u) AS userProps
RETURN u.id, flex.map.removeKey(userProps, 'password') AS safePropsMATCH (p:Product {id: 123})
WITH properties(p) AS props
WITH flex.map.removeKey(props, 'internalId') AS cleaned
RETURN cleaned AS productWITH {a: 1, b: 2} AS map
RETURN flex.map.removeKey(map, 'c') AS resultOutput:
result
---------
{a: 1, b: 2}
(Key doesn't exist, so map is returned unchanged)
- Returns empty map if input is not a valid object or is
null - If key is
null, returns a shallow copy of the map - If the key doesn't exist, returns a copy with all original properties
- Creates a new map; does not modify the original
- Useful for sanitizing data, removing sensitive fields, or filtering properties
- map.removeKeys - Remove multiple keys at once
- map.submap - Keep only specific keys (inverse operation)
- map.merge - Combine multiple maps