我正在尝试创建一个无声拍卖网站。我的Lambda函数应在提交的出价>条件下更新项目。当前的高出价。然而,这个条件似乎没有适用;即使提交的出价低于当前的高出价,也会进行更新。 请帮我确定一下我做错了什么:
##我的DynamoDB表如下所示:##
如上所述,我的条件是传入的event.NewBid大于CurrentHighBid。这是Node.JS中的Lambda代码:
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
exports.handler = function index(event, context, callback) {
var table = "SilentAuction2";
var ItemID = event.ItemID;
var NewBid = event.NewBid;
var NewBidder = event.NewBidder;
var Notes = event.Notes;
var params = {
TableName:table,
Key:{
"ItemID": ItemID
},
//update and append values
UpdateExpression: "SET #BidList = list_append(#BidList, :hb),
#PplList = list_append(#PplList, :hp),
CurrentHighBid =:c,
HighestBidder=:h,
Notes=:n",
//condition on which to update if true
ConditionalExpression: " :c > CurrentHighBid",
ExpressionAttributeNames: {
"#BidList" : "BidHistoryBids",
"#PplList" : "BidHistoryPPL"
},
ExpressionAttributeValues:{
":hb":[NewBid],
":hp":[NewBidder],
":n":Notes,
":c":NewBid,
":h":NewBidder
},
ReturnValues:"UPDATED_NEW"
};
docClient.update(params, function(err, data){
if(err){
callback(err, null);
}else{
callback(null, data);
}
});
};
此链接有助于研究DynamoDB中的ConditionalExpression: https://egkatzioura.com/2016/08/09/update-dynamodb-items-with-node-js/