这里是 的定义ConditionExpression
。
条件更新成功必须满足的条件。
看下面的条件表达式。最初,表中的项目具有以下值:-
UsageCount
= 1
EntitilementCount
= 5
局部变量: askedCount
= 1(即值加 1)
var params = {
TableName: "tableName",
Key: {
"ID": '3'
},
UpdateExpression: "SET UsageCount = UsageCount + :askedCount",
ConditionExpression : "UsageCount < EntitilementCount",
ExpressionAttributeValues: {
":askedCount": askedCount,
},
ReturnValues: "UPDATED_NEW"
};
我已成功执行该程序 4 次。第五次,我收到了The conditional request failed
错误消息。这满足您的要求。
prompt>node updateitem_stock_conditionally.js
Updating the item...
UpdateItem succeeded: {"Attributes":{"UsageCount":2}}
prompt>node updateitem_stock_conditionally.js
Updating the item...
UpdateItem succeeded: {"Attributes":{"UsageCount":3}}
prompt>node updateitem_stock_conditionally.js
Updating the item...
UpdateItem succeeded: {"Attributes":{"UsageCount":4}}
prompt>node updateitem_stock_conditionally.js
Updating the item...
UpdateItem succeeded: {"Attributes":{"UsageCount":5}}
prompt>node updateitem_stock_conditionally.js
Updating the item...
Unable to update item. Error JSON: {
"message": "The conditional request failed",
"code": "ConditionalCheckFailedException",
"time": "2017-04-26T20:29:21.710Z",
"requestId": "d73571f3-17f3-4aca-a3cf-7f13019a0292",
"statusCode": 400,
"retryable": false,
"retryDelay": 0
}