apoc.map.updateTree

Details

Syntax

apoc.map.updateTree(tree, key, data)

Description

Adds the data MAP on each level of the nested tree, where the key-value pairs match.

Arguments

Name

Type

Description

tree

MAP

The map to be updated.

key

STRING

The name of the key to match on.

data

LIST<LIST<ANY>>

A list of pairs, where the first item is the value to match with the given key, and the second is a map to add to the tree.

Returns

MAP

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;
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
  }
}