apoc.map.updateTree

Function APOC Core

apoc.map.updateTree(tree,key,) returns map - adds the {data} map on each level of the nested tree, where the key-value pairs match

Signature

apoc.map.updateTree(tree :: MAP?, key :: STRING?, data :: LIST? OF LIST? OF ANY?) :: (MAP?)

Input parameters

Name Type Default

tree

MAP?

null

key

STRING?

null

data

LIST? OF LIST? OF ANY?

null

Usage Examples

The following updates a nested map, adding additional key/values based on the value of the id key:

RETURN apoc.map.updateTree({
  id:1,
  c:{
    id:2
  },
  d:[
    {id:3},
    {id:4}
  ],
  e: {notId: 5}
},'id',[
  [1,{description: "Added where id=1"}],
  [2,{description: "Added where id=2"}],
  [3,{description: "Added where id=3"}],
  [4,{description: "Added where id=4"}]
]) AS value;
Table 1. Results
Output
{
  "id": 1,
  "description": "Added where id=1",
  "c": {
    "id": 2,
    "description": "Added where id=2"
  },
  "d": [
    {
      "id": 3,
      "description": "Added where id=3"
    },
    {
      "id": 4,
      "description": "Added where id=4"
    }
  ],
  "e": {
    "notId": 5
  }
}