My updateItem params is like this:
{
TableName: 'tablename',
Key: {
pk: {
S: 'string'
},
sk: { S: '2022-06-13' }
},
UpdateExpression: 'ADD #views :amount',
ExpressionAttributeNames: { '#views': 'views' },
ExpressionAttributeValues: {
':amount': { N: '1' }
}
}
Somehow, I got this error:
ValidationException: Invalid UpdateExpression:
Incorrect operand type for operator or function;
operator: ADD, operand type: MAP, typeSet: ALLOWED_FOR_ADD_OPERAND
It works when I pass directly the values ('value'
) instead of using AttributeValue
s ({S: 'value'}
) in my param like this:
{
TableName: 'tablename',
Key: {
pk: 'my-pk',
sk: '2022-06-13'
},
UpdateExpression: 'ADD #views :amount ',
ExpressionAttributeNames: { '#views': 'views'},
ExpressionAttributeValues: {
':amount': 1
}
}
My code is like this:
try {
const docClient = new AWS.DynamoDB.DocumentClient();
await docClient.update(params).promise();
} catch (e) {
console.error(e);
}