33
votes

I am trying to update an item in DynamoDB table:

var params = {
        TableName: 'User',
    Key: {
        id: 'b6cc8100-74e4-11e6-8e52-bbcb90cbdd26',
    },
    UpdateExpression: 'ADD past_visits :inc, past_chats :inc',
    ExpressionAttributeValues: {
        ':inc': 1
    },
        ReturnValues: 'ALL_NEW'
    };
    docClient.update(params, function(err, data) {
        if (err) ppJson(err); // an error occurred
        else ppJson(data); // successful response
    });        

It's working. But I want to set some more value (reset_time = :value') like this:

var params = {
        TableName: 'User',
    Key: {
        id: 'b6cc8100-74e4-11e6-8e52-bbcb90cbdd26',
    },
    UpdateExpression: 'ADD past_visits :inc, past_chats :inc, SET reset_time = :value',
    ExpressionAttributeValues: {
        ':inc': 1,
        ':value': 0
    },
        ReturnValues: 'ALL_NEW'
    };
    docClient.update(params, function(err, data) {
        if (err) ppJson(err); // an error occurred
        else ppJson(data); // successful response
    });

Can DynamoDb support multi action in one query ?

1
May I request to accept the answer if it is useful? Thanks! - notionquest

1 Answers

85
votes

Please change the update expression as mentioned below. It should work.

There is no comma between second ":inc" and SET.

UpdateExpression : "ADD past_visits :inc, past_chats :inc  SET reset_time = :value",