apoc.map.renameKey

函数 Apoc 扩展

重命名 MAP 中的给定键。

签名

apoc.metrics.get(map :: MAP?, keyFrom :: STRING?, keyTo :: STRING?, config = {} :: MAP?) :: MAP?

输入参数

名称 类型 默认

Map

MAP?

null

keyFrom

STRING?

null

keyTo

STRING?

null

config

MAP?

{}

配置参数

表 1. 配置参数
名称 (name) type 默认 description(描述)

recursive

boolean

true

搜索需要重命名的键,甚至是在子映射或映射列表内进行搜索

使用示例

apoc.map.renameKey (默认配置)
WITH {
    old_key: [1, "test", {old_key: "some_value"}],
    otherKey: [1, ["test", {old_key: "some_value"}]],
    name: {old_key: "some_value"},
    other: "key"
 } AS map
RETURN apoc.map.renameKey(map, "old_key", "new_key") as value
表 2. 结果
{
  "new_key": [
    1,
    "test",
    {
      "new_key": "some_value"
    }
  ],
  "other": "key",
  "otherKey": [
    1,
    [
      "test",
      {
        "new_key": "some_value"
      }
    ]
  ],
  "name": {
    "new_key": "some_value"
  }
}
apoc.map.renameKey (配置 recursive: false)
WITH {
    old_key: [1, "test", {old_key: "some_value"}],
    otherKey: [1, ["test", {old_key: "some_value"}]],
    name: {old_key: "some_value"},
    other: "key"
 } AS map
RETURN apoc.map.renameKey(map, "old_key", "new_key", {recursive: false}) as value
表 3. 结果
{
  "new_key": [
    1,
    "test",
    {
      "old_key": "some_value"
    }
  ],
  "other": "key",
  "otherKey": [
    1,
    [
      "test",
      {
        "old_key": "some_value"
      }
    ]
  ],
  "name": {
    "old_key": "some_value"
  }
}
© . This site is unofficial and not affiliated with Neo4j, Inc.