Amazon web services DynamoDB是否允许对除“以外的运算符进行有条件的更新?”=&引用;?
当且仅当内存计数器的值大于DynamoDB中存储的值时,我需要执行条件更新 示例-假设内存中计数器的值为30。DynamoDB中存储的计数器值为25。在1条件操作中,我想将DynamoDB值设置为30(因为25是一个旧值) 文件包括以下内容—Amazon web services DynamoDB是否允许对除“以外的运算符进行有条件的更新?”=&引用;?,amazon-web-services,amazon-dynamodb,Amazon Web Services,Amazon Dynamodb,当且仅当内存计数器的值大于DynamoDB中存储的值时,我需要执行条件更新 示例-假设内存中计数器的值为30。DynamoDB中存储的计数器值为25。在1条件操作中,我想将DynamoDB值设置为30(因为25是一个旧值) 文件包括以下内容— Expected allows you to provide an attribute name, and whether or not Amazon DynamoDB should check to see if the attribute value
Expected allows you to provide an attribute name, and whether or not Amazon DynamoDB should check to see if the attribute value already exists; or if the attribute value exists and has a particular value before changing it.
它清楚地表明,除非您知道旧值,否则u不能执行条件运算
是否有一个变通方法,我可以使用它对“大于”执行条件更新
感谢您的帮助
谢谢。你不能像文件中所说的那样用“原子操作”
如果不需要完整的原子特性,可以实现自己的“跨国”方法,或者使用(Java)DynamoDB确实支持其他操作符进行条件更新。对于这里讨论的情况,您需要在要计算的属性字段上指定一个条件运算符,条件“LT”(小于)内存计数器的值。在您的例子中,属性“myCounterName”小于30 在Java中(伪代码): 只有当DynamoDB中的当前计数器小于您指定的值时,此代码才会更新该计数器。
您所描述的内容在2014年4月24日发布的名为“改进的条件表达式”的版本中得到了本机支持。因此,您不再需要解决方法。感谢您向我介绍DynamoDB事务。将来,我希望DynamoDB也支持其他操作符上的条件更新。
ExpectedAttributeValue expectedValue = new ExpectedAttributeValue()
.withComparisonOperator(ComparisonOperator.LT)
.withAttributeValue(new AttributeValue().withN("30");
UpdateItemRequest request = new UpdateItemRequest(...);
request.addExpectedEntry("myCounterName", expectedValue);
dbClient.updateItem(request);