想要一个aws发电机的柜台吗

2024-05-15 09:47:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个列为“Name”和“Vote”的表,每当我更新_item时,我想增加投票数。我尝试了下面的问题,但没有运气。在

       db.update_item(Key={ "Name":"Dany"}, 
                      UpdateExpression='ADD #oldVote :newVote', 
                      ExpressionAttributeNames={ '#oldVote' :'Vote'}, 
                      ExpressionAttributeValues={':newVote': {"N": "1"}} 
                      )

获取错误为:

"An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: MAP"

error


Tags: nameadddbtypeupdateerroritemoperator
2条回答

请尝试下面的更新。它应该能解决问题。在

db.update_item(Key={ "Name":"Dany"}, 
              UpdateExpression='SET #oldVote = #oldVote + :newVote', 
              ExpressionAttributeNames={ '#oldVote' :'Vote'}, 
              ExpressionAttributeValues={':newVote': 1} 
              )

您可以尝试以下操作:

db.update_item(Key={ "Name":"Dany"}, 
                  UpdateExpression='SET Vote = Vote + :incr', 
                  ExpressionAttributeValues={':incr': {"N": "1"}} 
                  )

来源:http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters

相关问题 更多 >