如何一次更新DynamoDB表中的多个项目 [英] How to update multiple items in a DynamoDB table at once

查看:67
本文介绍了如何一次更新DynamoDB表中的多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DynamoDB,并且需要更新多个记录上的特定属性。用伪语言编写我的要求,我想做一个更新,说更新表 persons set relationshipStatus ='married'where personKey IN(key1,key2,key3,...)(假定该personKey是我的DynamoDB表中的KEY)。

I'm using DynamoDB and I need to update a specific attribute on multiple records. Writing my requirement in pseudo-language I would like to do an update that says "update table persons set relationshipStatus = 'married' where personKey IN (key1, key2, key3, ...)" (assuming that personKey is the KEY in my DynamoDB table).

换句话说,我想用一条子句进行更新,或者我想可以将其称为a批量更新。我找到了链接,该链接明确询问是否存在诸如批处理更新之类的操作,答案是它不是。但是,它没有提及IN条款。 文档显示,ConditionalExpression支持子句(一次可以提供100个值)。但是,我不确定这样的IN子句是否适合我的情况,因为我仍然需要提供一个强制性的KEY属性(该属性期望一个似乎是单个值-我可能错了),并且我担心它会做一个

In other words, I want to do an update with an IN-clause, or I suppose one could call it a batch update. I have found this link that asks explicitly if an operation like a batch update exists and the answer there is that it does not. It does not mention IN-clauses, however. The documentation shows that IN-clauses are supported in ConditionalExpressions (100 values can be supplied at a time). However, I am not sure if such an IN-clause is suitable for my situation because I still need to supply a mandatory KEY attribute (which expects a single value it seems - I might be wrong) and I am worried that it will do a full table scan for each update.

所以我的问题是:如何同时对多个DynamoDB记录进行更新?此刻,我几乎不得不逐个调用每个Key的更新语句,感觉真是不对劲...

So my question is: how do I achieve an update on multiple DynamoDB records at the same time? At the moment it almost looks like I will have to call an update statement for each Key one-by-one and that just feels really wrong...

推荐答案

如您所述,DynamoDB不支持批量更新操作。您将需要查询并获取要更新的所有记录的键。然后遍历该列表,一次更新每个项目。

As you noted, DynamoDB does not support a batch update operation. You would need to query for, and obtain the keys for all the records you want to update. Then loop through that list, updating each item one at a time.

这篇关于如何一次更新DynamoDB表中的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆