首页 > 解决方案 > 更新 DynamoDB 中的列表

问题描述

我在 SO 中尝试了多种解决方案,但遇到了一个验证错误:这是我的表:

var params = {
    AttributeDefinitions: [
        {
            AttributeName: 'USER_AUTH_ID',
            AttributeType: 'N'
        },
        {
            AttributeName: 'EMAIL',
            AttributeType: 'S'
        }
    ],
    KeySchema: [
        {
            AttributeName: 'EMAIL',
            KeyType: 'HASH'
        },
        {
            AttributeName: 'USER_AUTH_ID',
            KeyType: 'RANGE'
        }
    ],
    ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    },
    TableName: tableName,
    StreamSpecification: {
        StreamEnabled: false
    }
};

我已经使用 putItem 成功创建了项目,但无法附加到列表:

这是我要更新的项目:

var paramUpdateItem = {
    TableName: tableName,
    Key: {
        'EMAIL' : {S: 'MyEmail@email.com'}
    },
    UpdateExpression: "SET #Y = list_append(#Y,:y)",
    ExpressionAttributeNames: {
        "#Y" : "COMMENT_HISTORY"
    },
    ExpressionAttributeValues: {
        ":y" : [commentToAdd]
    }
}

;

我用updateItem.

我不断收到此错误:

null:错误:在 params.ExpressionAttributeValues[':y'] 中找到意外的键“0”

我在另一个问题中读到这是由于标签,但我试图修复它但仍然收到此错误。

任何帮助。谢谢你。

标签: javascriptnode.jsamazon-dynamodb

解决方案


I cant think of two options. One is that this is a library bug, as you said it might be "due to tabs", see for example this issue claiming that this is a bug with whitespace and suggesting workarounds:

https://github.com/aws/aws-sdk-js/issues/2546

Another option is that you are using the low-level API (you didn't show how you made the query). In the low-level API, you can't just say {":y" : [commentToAdd]}. You need to say that this list is, in fact, a list, and what are the types of its components. Something like {':y': {'L': [{'S', 'word1'}, {'S', 'word2'} ] }.


推荐阅读