【问题标题】:Rename a field within an array in DocumentDB via pymongo通过 pymongo 重命名 DocumentDB 中数组中的字段
【发布时间】:2022-03-01 00:29:05
【问题描述】:

我在 AWS 中使用 docudmentDB(版本 3.6)。我在 AWS 中使用 python lambda 来完成这项任务。任务是重命名数组中的字段。这是我拥有的示例 JSON 文档。这里我需要将'version'重命名为'label'。

{
  "_id": "93ee62b2-4a1f-478f-a716-b4e2f435f27d",
  "egrouping": [
    {
      "type": "Video",
      "language_code": "eng",
      "hierarchy": {
        "pype": {
          "parent": "episode",
          "version": "1",
          "uuid": "933433-4a1f-478f-a716-b4e2f435f27d"
        }
      }
    },
    {
      "type": "Captions",
      "language_code": "eng",
      "hierarchy": {
        "pype": {
          "parent": "episode",
          "version": "1",
          "uuid": "943454-4a1f-478f-a716-b4e2f435f27d"
        }
      }
    }
  ]
}

以下代码sn-p我尝试重命名'version'字段出现错误:

collection.aggregate([
    {
        '$project': {
           'egrouping': {
               '$map': {
                   "input": "$egrouping",
                   'as': "egroup",
                   'in': {
                       "hierarchy.pype.label": "$$egroup.hierarchy.pype.version"
                   }
               }
           }
        }
    }
    ])

但我最终得到了这个错误:

  "errorMessage": "Aggregation project operator not supported: '$map'",

【问题讨论】:

    标签: mongodb-query aws-documentdb aws-documentdb-mongoapi


    【解决方案1】:

    Amazon DocumentDB 不支持 $map。有关 DocumentDB 支持的 API 的完整列表,请参阅https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html

    我们一直在从客户希望使用的 API 倒退。你可以在这里关注我们未来的发布https://aws.amazon.com/documentdb/resources/

    【讨论】:

      【解决方案2】:

      $map 运算符现在是 supported,在 Amazon DocumentDB 版本、3.64.0 中。

      【讨论】:

        猜你喜欢
        • 2023-04-05
        • 2016-01-27
        • 2019-01-27
        • 1970-01-01
        • 2013-01-05
        • 2015-10-19
        • 2021-06-08
        • 2012-02-25
        • 2019-12-06
        相关资源
        最近更新 更多