TahuaOne
TahuaOne

Reputation: 11

JavaScript DynamoDB UpdateItem ADD UpdateExpression

I am running into an issue with the JavaScript v3 client for DynamoDB. According to the AWS documentation, I should be able to create an UpdateExpression which uses an ADD keyword to add an element to a list. When attempting this, it throws an error not recognizing the update expression.

If I run the same command using SET instead of ADD it works just fine, however, SET as noted in the documentation replaces the current value, and does not add to the list.

The Error:

"errorMessage": "Invalid UpdateExpression: Syntax error; token: \"=\", near: \"activeUsers = :au\"",

The Code:

const joinParams = {
    TableName: tableName,
    Key: {
        id: myTable.Items[0].id
    },
    UpdateExpression: "SET activeUsers = :ac",
    ExpressionAttributeValues: {
        ":ac": [user]
    }
};

await docClient.update(joinParams).promise();

Upvotes: 0

Views: 1105

Answers (1)

Micky
Micky

Reputation: 572

Take a look at the answer to a similar question here.

I think your syntax after the ADD is slightly off.

UpdateExpression: "ADD activeUsers :ac", <!-- remove the "="

Upvotes: 0

Related Questions