apoc.map.updateTree

详细信息

语法

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

描述

在嵌套树的每一层中,当键值对匹配时,添加数据 MAP

参数

名称

类型

描述

tree

MAP

要更新的 Map。

键 (key)

STRING

用于匹配的键名。

data

LIST<LIST<ANY>>

一个列表对,其中第一项是与给定键匹配的值,第二项是要添加到树中的 map。

返回

MAP

使用示例

以下示例更新了一个嵌套 map,根据 id 键的值添加额外的键/值。

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;
结果
输出
{
  "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
  }
}