> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# map.merge

> Performs a shallow merge of multiple maps, with later map values overriding earlier ones on key conflicts.

## Description

Performs a shallow merge of multiple maps into a new map. When keys conflict, values from later maps override earlier ones. Non-object inputs are ignored.

## Syntax

```cypher theme={null}
flex.map.merge(map1, map2, ...)
```

## Parameters

| Parameter | Type | Required | Description              |
| --------- | ---- | -------- | ------------------------ |
| `map1`    | map  | No       | First map to merge       |
| `map2`    | map  | No       | Second map to merge      |
| `...`     | map  | No       | Additional maps to merge |

## Returns

**Type:** map (object)

A new map containing all keys and values from the input maps. Later maps override earlier ones for duplicate keys.

## Examples

### Example 1: Basic Merge

```cypher theme={null}
WITH {a: 1, b: 2} AS map1, {b: 3, c: 4} AS map2
RETURN flex.map.merge(map1, map2) AS result
```

**Output:**

```text theme={null}
result
------------------
{a: 1, b: 3, c: 4}
```

(Note: `b` from map2 overrides `b` from map1)

### Example 2: Merging Node Properties

```cypher theme={null}
MATCH (u:User {id: 123})
WITH {role: 'admin', status: 'active'} AS defaults
RETURN flex.map.merge(defaults, properties(u)) AS userWithDefaults
```

### Example 3: Combining Configuration

```cypher theme={null}
WITH {host: 'localhost', port: 6379} AS defaults,
     {port: 7000, password: 'secret'} AS config
RETURN flex.map.merge(defaults, config) AS finalConfig
```

**Output:**

```text theme={null}
finalConfig
--------------------------------------------------
{host: 'localhost', port: 7000, password: 'secret'}
```

### Example 4: Merging Multiple Maps

```cypher theme={null}
WITH {a: 1} AS base, {b: 2} AS extra1, {c: 3} AS extra2
RETURN flex.map.merge(base, extra1, extra2) AS combined
```

## Notes

* Non-object inputs are silently ignored
* Performs shallow merge (nested objects are not deeply merged)
* Later maps take precedence for duplicate keys
* Returns a new map; does not modify input maps
* Useful for applying defaults, combining configuration, or merging properties

## See Also

* [map.submap](/udfs/flex/map/submap) - Extract specific keys from a map
* [map.removeKeys](/udfs/flex/map/removeKeys) - Remove keys from a map

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="Does flex.map.merge do a deep or shallow merge?">
    It performs a **shallow** merge. Nested maps are not recursively merged — values from later maps overwrite those from earlier maps.
  </Accordion>

  <Accordion title="Can I merge more than two maps?">
    Yes. You can pass multiple maps as arguments to merge them all in sequence.
  </Accordion>
</AccordionGroup>
