Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB UpdateException: Type mismatch for attribute to update

I have the following record in DynamoDB:

    {
        "BusinessNo": {
            "N": "12345"
        },
        "Metadata": {
            "M": {
                "MimeType": {
                    "S": "audio/wav"
                },
                "FileName": {
                    "S": "00032329.wav"
                },
                "CustomC": {
                    "S": "baz"
                },
                "CustomA": {
                    "S": "foo"
                },
                "CustomB": {
                    "S": "bar"
                },
                "Size": {
                    "S": "3992020323"
                }
            }
        },
        "Id": {
            "S": "f0de8af3-a7f5-4d9b-ad5d-b2f150abd15e"
        },
        "Revision": {
            "N": "2"
        }
    }

But when I submit the following using the update method of DynamoDB.DocumentClient from the nodejs AWS SDK (I have also tried add instead of set):

{
  "TableName": "Storage_FileMetadata",
  "Key": {
    "Id": "f0de8af3-a7f5-4d9b-ad5d-b2f150abd15e",
    "BusinessNo": "12345"
  },
  "ExpressionAttributeNames": {
    "#m": "Metadata",
    "#k": "CustomD",
    "#r": "Revision"
  },
  "ExpressionAttributeValues": {
    ":r": 4,
    ":v": "doo-wop"
  },
  "UpdateExpression": "set #m.#k = :v",
  "ConditionExpression": "#r < :r"
}

I get the following exception:

{
    "message": "Type mismatch for attribute to update",
    "code": "ValidationException",
    "time": "2016-11-11T18:55:01.543Z",
    "requestId": "b9d78c87-1c4d-400a-8968-d761b657cd53",
    "statusCode": 400,
    "retryable": false,
    "retryDelay": 0
}

I think I'm missing something about adding/updating nested attributes but after reading the docs I can't figure out what.

like image 735
Mark J Miller Avatar asked Nov 11 '16 19:11

Mark J Miller


1 Answers

Seems that you need to send the value "BusinessNo": "12345" as a number

"Key": {
    "Id": "f0de8af3-a7f5-4d9b-ad5d-b2f150abd15e",
    "BusinessNo": 12345
}
like image 130
Hug Arias Avatar answered Oct 25 '22 01:10

Hug Arias