amazon-dynamodb - DynamoDB PutItem 然后 UpdateItem 与 ReturnValues ALL_NEW 的一致性

标签 amazon-dynamodb consistency eventual-consistency

当使用 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/

相关文章:

amazon - DynamoDB 是否仍然遵循 CAP 定理及其 "Strong Consistency" promise ?

Cassandra - 一致性顺序

apache-kafka - 微服务数据复制模式

heroku - Heroku Dynos 是否享受 AWS 网络内的免费数据传输?

javascript - 集合并集查询

prolog - CLP(FD) 可变域和传播

C 语法 : Is the following 'extern volatile const' behavior consistent among C compilers?

windows - DynamoDb SocketException : A socket operation was attempted to an unreachable network

django - AWS 上 Django 的最佳数据库解决方案

cassandra - 完全复制的 Cassandra 集群上非主键查询的性能