amazon-dynamodb - DynamoDB PutItem 然后 UpdateItem 与

当使用 PutItem 添加新项目,然后使用返回值设置为 ALL_NEWUpdateItem 更新它时,是否期望返回值会强一致吗?

例如放置一个元素;

{key: 1a a: 1}

然后更新项目;

{key: 1, b: 2}

我希望 ReturnValues: ALL_NEW 返回

{key: 1, a: 1, b: 2}

但事实并非如此?

最佳答案

我已经在成功执行 put item 时更新了 item 并得到了您预期的结果。

注意:测试在 DynamoDB 本地执行。

ALL_NEW - Returns all of the attributes of the item, as they appear after the UpdateItem operation.

示例代码:-

var docClient = new AWS.DynamoDB.DocumentClient();

var table = "post";

var paramsPut = {
    TableName: table,
    Item: {
        "postId": '16',
        "Pos": {
            "key": "1a", "a": "1"
        }
    }
};

var paramsUpdate = {
    TableName: "post",
    Key: {
        "postId": "16"
    },
    UpdateExpression: "SET Pos.#key = :keyVal, Pos.b = :keyVal2",
    ExpressionAttributeNames: {
        "#key": "key"
    },
    ExpressionAttributeValues: {
        ":keyVal": "1",
        ":keyVal2": "2"
    },
    ReturnValues: "ALL_NEW"
};

console.log("Adding a new item...");
docClient.put(paramsPut, function (err, data) {
    if (err) {
        console.error("Unable to add item. Error JSON:", JSON.stringify(err,
            null, 2));
    } else {
        console.log("Added item:", JSON.stringify(data, null, 2));

        console.log("Then Updating the item...");
        docClient.update(paramsUpdate, function (err, data) {
            if (err) {
                console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
            } else {
                console.log("UpdateItem succeeded:", JSON.stringify(data));
            }
        });
    }
});

输出:-

Adding a new item...
Added item: {}
Then Updating the item...
UpdateItem succeeded: {"Attributes":{"Pos":{"a":"1","b":"2","key":"1"},"postId":
"16"}}

关于amazon-dynamodb - DynamoDB PutItem 然后 UpdateItem 与 ReturnValues ALL_NEW 的一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45728858/

相关文章:

mysql - phpmyadmin error 403 - Forbidden rejected

node.js - 更新 Docker 镜像中的 npm

Angular 2 - 如何将响应式(Reactive)表单元素动态绑定(bind)到事件?

angular - 将 CanActivate() 委托(delegate)给组件

rest - Django REST 框架 RequestsClient 内容类型

amazon-web-services - 如何将多个域名路由到同一个 amazon S3 存储桶位

vb.net - 字符串中的代码格式 - 我可以将文本设为粗体吗?

java - 如何配置 Hibernate Envers 以避免实体修订查询中的某些集合(连接表)

reactjs - 从 create-react-app 发出构建文件

python-3.x - Visual Studio 代码 pylint : Error when