您如何使用条件而不是密钥更新AWS DynamoDB
您如何按照条件而不是密钥来更新DynamoDB表?我想将所有 active 标志设置为false,其中 gameid = xxxx和 age > 30。
How do you go about updating a DynamoDB table by condition and not a key? I want to set all active flags to false where gameid = xxxx and age > 30.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设计DynamoDB模式时,您需要与设计关系模式不同。关系数据库对小数据集有用,您可以简单地浏览所有记录并更新其中的一些值。但是,它并不适用于数百万和更多的记录,您需要以不同的方式思考并使用NOSQL解决方案,例如DynamoDB。
DynamoDB的主要功能是几乎无限的查找操作量表,这些量表大多是单个或一组记录的量表。评论中提出的问题的解决方案很好,您可以:
select * select *从“ games”中找到gameid =“ xxxx”和年龄> 30和flag =“ Active”
,但是您应该考虑对桌子的不同设计,并考虑批量更新的原因。也许您应该还有另一个表,您可以简单地更新单个记录以应用所需的更改。例如,如果记录是称为
round
的对象的一部分,请将记录指向此对象,并在需要时更新此单个回合记录的状态。阅读两个记录(一个用于游戏,一个用于圆形)非常容易,而不仅仅是一个游戏记录。特别是,如果您可以最大程度地降低使用这样的标志更新许多游戏记录的复杂性和成本。
When you design a DynamoDB schema you need to think differently than when you design a relational schema. Relational databases are good for small datasets, where you can simply go over all the records and update some values in them. However, it doesn't scale for millions and more records, and you need to think differently and use a NoSQL solution such as DynamoDB.
The main power of DynamoDB is the almost unlimited scale of LOOKUP operations that are mostly GET and PUT of a single or a small set of records. The solutions that were offered in the comments to the questions are good and you can:
SELECT * FROM "Games" WHERE gameid = "xxxx" and age > 30 and flag = "Active"
Nevertheless, you should consider a different design for your tables, and think about the reason for the bulk update. Maybe you should have another table where you can simply update a single record to apply the change that you want. For example, if the records are part of an object called
Round
, point the records to this object and update the state of this single round record when needed.It is very easy to read two records (one for game and one for round) instead of only a single record of a game. Especially, if you can minimize the complexity and cost of updating many records of games with such a flag.