通过 pymongo 重命名 DocumentDB 中数组中的字段

问题描述

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

{
  "_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","uuid": "943454-4a1f-478f-a716-b4e2f435f27d"
        }
      }
    }
  ]
}

以下代码片段我试图重命名出错的“版本”字段:

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

但我最终遇到了这个错误

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

解决方法

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

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