3

When adding a new item with PutItem and then updating it with UpdateItem which has a return values set to ALL_NEW is it expected that the return values will be strongly consistent?

For example Putting an item;

{key: 1a a: 1}

Then updating the item;

{key: 1, b: 2}

I would expect ReturnValues: ALL_NEW to return

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

But it would appear this is not the case?

NightWolf
  • 7,694
  • 9
  • 74
  • 121

1 Answers1

-2

I have updated the item on successful execution of put item and got the result as you expected.

Note: Testing performed on DynamoDB local.

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

Sample code:-

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));
            }
        });
    }
});

Output:-

Adding a new item...
Added item: {}
Then Updating the item...
UpdateItem succeeded: {"Attributes":{"Pos":{"a":"1","b":"2","key":"1"},"postId":
"16"}}
notionquest
  • 37,595
  • 6
  • 111
  • 105
  • 3
    Really this is a consistency question so I dont think you'd expect to see the same results with a actual DDB cluster – NightWolf Aug 17 '17 at 23:18