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

查看:30
本文介绍了如何一次更新 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).

换句话说,我想用 IN 子句进行更新,或者我想可以称之为批量更新.我发现 this 链接明确询问是否存在批量更新等操作,答案是它不是.然而,它没有提到 IN 子句.文档 表明条件表达式中支持 IN 子句(一次可以提供 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天全站免登陆