当且仅当内存中计数器的值大于存储在DynamoDB中时,我才需要执行条件更新。
示例 - 假设内存中计数器的值为30. DynamoDB中存储的计数器的值为25.在1个条件操作中,我想将DynamoDB值设置为30(因为25是旧值)< / p>
文档包含以下内容 -
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.
它明确指出,除非您知道旧值,否则您无法执行条件操作。
是否有一种解决方法可用于对'大于'进行条件更新?
感谢任何帮助。
感谢。
答案 0 :(得分:3)
http://aws.amazon.com/releasenotes/Amazon-DynamoDB/4503109122817643
您所描述的内容在2014年4月24日发布的版本中被称为&#34;改进的条件表达式&#34;。因此,您不再需要解决方法了。
答案 1 :(得分:0)
您不能使用documentation中所述的“原子操作”来执行此操作。
如果您不需要完全原子性质,您可以实施自己的“跨国”方法或使用one from amazon(Java)
答案 2 :(得分:0)
DynamoDB支持其他运营商进行条件更新。对于您在此处讨论的情况,您将在要评估的属性字段上指定条件运算符,并在条件“LT”(小于)内存计数器的值上指定。在您的情况下,属性“myCounterName”小于30。
在Java(伪代码)中:
ExpectedAttributeValue expectedValue = new ExpectedAttributeValue()
.withComparisonOperator(ComparisonOperator.LT)
.withAttributeValue(new AttributeValue().withN("30");
UpdateItemRequest request = new UpdateItemRequest(...);
request.addExpectedEntry("myCounterName", expectedValue);
dbClient.updateItem(request);
如果DynamoDB中的当前计数器小于您指定的值,此代码将仅更新该计数器。