apoc.map.mergeListFunction
Syntax |
|
||
Description |
Merges all |
||
Arguments |
Name |
Type |
Description |
|
|
A list of maps to merge. |
|
Returns |
|
||
Usage examples
The following merges multiple maps:
apoc.map.mergeList
WITH [
{name: "Cristiano Ronaldo"},
{dob: date("1985-02-05")},
{country: "Portugal"}
] AS maps
RETURN apoc.map.mergeList(maps) AS output
Cypher’s Map Comprehension
WITH [
{name: "Cristiano Ronaldo"},
{dob: date("1985-02-05")},
{country: "Portugal"}
] AS maps
WITH coll.flatten(collect([k IN keys(maps) | [k, maps[k]]]), 1) AS allEntries
RETURN { kv IN allEntries | kv[0] : kv[1]} AS output
| output |
|---|
{
"name": "Cristiano Ronaldo",
"country": "Portugal",
"dob": "1985-02-05"
}
|
apoc.map.mergeList iterates over the list sequentially as it merges.
This means that if the same key is used for different values, the last unique key-value pair in the list will be in the resulting map.
apoc.map.mergeList
WITH [
{name: "Cristiano Ronaldo"},
{dob: date("1985-02-05")},
{profession: "Athlete"},
{profession: "Football player"}
] AS maps
RETURN apoc.map.mergeList(maps) AS output
Cypher’s Map Comprehension
WITH [
{name: "Cristiano Ronaldo"},
{dob: date("1985-02-05")},
{profession: "Athlete"},
{profession: "Football player"}
] AS maps
WITH coll.flatten(collect([k IN keys(maps) | [k, maps[k]]]), 1) AS allEntries
RETURN { kv IN allEntries | kv[0]: kv[1]} AS output
| output |
|---|
{
"name": "Cristiano Ronaldo",
"profession": "Football player",
"dob": "1985-02-05"
}
|