Map Functions
|
flatten a nested map into a single-level map, for example turning {parent:{child:1}} into {"parent.child":1} |
|
creates map from nodes with this label grouped by property |
|
creates map from list with key-value pairs |
|
creates map from a keys and a values list |
|
creates map from alternating keys and values in a list |
|
creates map from merging the two source maps |
|
merges all maps in the list into one |
|
returns the map with the value for this key added or replaced |
|
returns the map with the key removed (recursively if recursive is true) |
|
returns the map with the keys removed (recursively if recursive is true) |
|
removes the keys and values (e.g. null-placeholders) contained in those lists, good for data cleaning from CSV/JSON |
|
creates a map of the list keyed by the given property, with single values |
|
creates a map of the list keyed by the given property, with list values |
|
returns a list of key/value list pairs, with pairs sorted by keys alphabetically, with optional case sensitivity |
returns map - adds the {data} map on each level of the nested tree, where the key-value pairs match |
|
|
returns list of values indicated by the keys |
returns submap for keys or throws exception if one of the key doesn’t exist and no default value given at that position |
|
returns list of values for keys or throws exception if one of the key doesn’t exist and no default value given at that position |
|
|
returns value for key or throws exception if key doesn’t exist and no default given |
RETURN apoc.map.fromPairs([
["name", "Cristiano Ronaldo"],
["age", date("1985-02-05")]
]) AS output
Output |
---|
|
RETURN apoc.map.fromValues([
"name", "Cristiano Ronaldo",
"age", date("1985-02-05")
]) AS output
Output |
---|
|
RETURN apoc.map.fromLists(
["name", "dob"],
["Cristiano Ronaldo", date("1985-02-05")]
) AS output
Output |
---|
|
RETURN apoc.map.merge(
{name: "Cristiano Ronaldo", dob: date("1985-02-05")},
{country: "Portugal"}
) AS output
Output |
---|
|
RETURN apoc.map.mergeList([
{name: "Cristiano Ronaldo"},
{dob: date("1985-02-05")},
{country: "Portugal"}
]) AS output
Output |
---|
|
RETURN apoc.map.setKey(
{name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")},
"dob",
date("1986-02-06")
) AS output
Output |
---|
|
RETURN apoc.map.removeKey(
{name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")},
"dob"
) AS output
Output |
---|
|
RETURN apoc.map.removeKeys(
{name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")},
["dob", "country"]
) AS output
Output |
---|
|
RETURN apoc.map.clean({name: "Cristiano Ronaldo", club: ""}, [], [""]) AS output
Output |
---|
|
dob
and country
from a map:RETURN apoc.map.clean(
{name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05"), club: ""},
["dob", "country"],
[""]
) AS output
Output |
---|
|
WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.sortedProperties(map) AS output
Output |
---|
[["country","Portugal"],["dob","1985-02-05"],["name","Cristiano Ronaldo"]] |
club
, with list valuesRETURN apoc.map.groupByMulti([
{name: "Cristiano Ronaldo", club: "Juventus"},
{name: "Lionel Messi", club: "Barcelona"},
{name: "Aaron Ramsey", club: "Juventus"},
{name: "Luiz Suarez", club: "Barcelona"}
], "club") AS output
Output |
---|
|
name
and country
, and a null
value for missing key missingKey
:WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.values(map, ["name", "country", "missingKey"], true) AS output
Output |
---|
["Cristiano Ronaldo","Portugal",null] |
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 |
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" |
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"] |
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"] |