[英]AWS DynamoDB create update expression - Add new stringset if none exists
我正在尝试创建一个更新,如果该字符串集存在,则将电子邮件添加到该字符串集;如果不存在,则使用该电子邮件创建一个字符串集。
我从此答案中获取了一些代码: 如果不存在,请追加或创建StringSet,但我似乎无法使其工作。
我最终"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: MAP" }
错误"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: MAP" }
response = table.update_item(
Key={'email':email},
UpdateExpression='ADD emails :i',
ExpressionAttributeValues={
':i': {SS': [email]},
},
ReturnValues="UPDATED_NEW"
)
如何创建一个更新表达式以创建一个不存在的字符串集,或者如果存在则添加一个项目?
我本周也遇到了同样的问题,后来我找到了一个解决方案。 看下面的例子:
response = table.update_item(
Key={'email': email },
UpdateExpression="ADD emails :i",
ExpressionAttributeValues={":i": set([email])},
ReturnValues="UPDATED_NEW"
)
这对我来说可以创建字符串集或附加到现有的字符串集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.