更新发电机数据库中的项目时出错



我创建了一个简单的表(username,password),关键是username。该表包含一项:{"username":"someuser","密码":"猫"}

现在,我想从"猫"更新为"狗"

dynamodb.updateItem({
    TableName: "users",
    Key: { "username": { "S" : "someuser" } },
    UpdateExpression : "SET password =:pass",
    ExpressionAttributeValues : { ":pass" : { "S" : "dog" } }
}, function(err, data) {
    if (err)
        console.log(JSON.stringify(err, null, 2));
    else
        console.log(JSON.stringify(data, null, 2));
});

但我得到了错误:

{
  "message": "Invalid attribute value type",
  "code": "ValidationException",
  "time": "2015-11-14T20:22:36.381Z",
  "statusCode": 400,
  "retryable": false
}

最后,我发现dynamodb javascript shell与在AWS上运行的dynamodb不同。

在实际发电机数据库中没有出现上述错误。

编辑:例如,以下作品:

       var params = {
            TableName: config.SCRIPTTABLE,
            Key: { id : { S: script.id }},
            UpdateExpression: "SET title = :title, description = :desc, code = :code, tags = :tags, pub = :pub",
            ExpressionAttributeValues: {
                ":title":   { S: script.title },
                ":desc" :   { S: script.description },
                ":code" :   { S: script.code },
                ":tags" :   { SS: script.tags },
                ":pub"  :   { BOOL: script.pub }
            },
            ReturnValues: "ALL_NEW"
        };
        dynamodb.updateItem(params, function(err, data)  {
            if (err) {
                console.log(JSON.stringify(err));
                context.fail('INTERNAL_SERVER_ERROR');
            } else {
                context.succeed();
            }
        });

最新更新