mongodb-queryaws-documentdbaws-documentdb-mongoapi

Rename a field within an array in DocumentDB via pymongo


I am using docudmentDB(version 3.6) in AWS. I use a python lambda in AWS for this task. The task is to rename a field that is in an array. Here is the sample JSON document I have. Here I need to rename 'version' to '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"
        }
      }
    }
  ]
}

The following code snippet I tried to rename the 'version' field which is in an error:

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

But I end up with this error:

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

Solution

  • Amazon DocumentDB does not support $map. For the complete list of APIs that DocumentDB supports, refer to https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html.

    We are constantly working backwards from the APIs our customers are looking to use. You can keep an eye on our future launches here https://aws.amazon.com/documentdb/resources/