如何在DynamoDB中存储大型阵列
我是DynamoDB的新手,我很好奇存储潜在大型阵列的最佳方法是什么。
我有一个看起来像这样的用户对象:
UserId: String
Watching: Card[]
Listings: Card[]
我知道发电机中对象的大小有限制 - 我认为1MB?因此,我认为如果用户有很多列表,它可能会超过此限制。 存储像这样的潜在大型阵列的最佳做法是什么? 可能是存储一系列Cardids,然后进行第二个查询以从中获得卡片?
I am new to DynamoDB and I am curious what is the best way to store potentially large arrays.
I have a user object that looks like this:
UserId: String
Watching: Card[]
Listings: Card[]
I am aware there is a limit to the size of objects in Dynamo - I think 1MB? Therefore I think if a user had many listings it might go past this limit.
What would be the best practice to store potential large arrays like this?
Would it be to maybe store an array of CardIds and then do a second query to get cards from this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种选项是使用单个表设计,列表在同一张表中。
用户项将具有
用户#UID
的主要键,而用户#UID
(与PK相同)的SK,每个观看项目都有用户的PK #UID
和的SK>观看#wid
,每个列表都有用户#uid
和listing#lid 。
例如:
方法对观看或列表关系的数量没有真正的限制。
然后,您只需通过发布
pk =用户#42
的查询来查询给定用户的所有项目,这将产生用户以及所有关联的观看和列表项目(尽管有分页)。您可以使用pk =用户#42
和sk begins_with(“ listing#”)
查询给定用户的所有列表。请注意,由于属性值的其他“用户”,“观看”和“清单”前缀,因此这将增加表大小,因此您可能需要考虑缩写这些。
引用亚历克斯·德布里(Alex Debrie):
One option is to use the Single Table Design approach where all users, watchings, and listings are in the same table.
User items would have a primary key of
user#uid
and sk ofuser#uid
(the same as pk), each watching item would have a pk ofuser#uid
and sk ofwatching#wid
, and each listing would have a pk ofuser#uid
and sk oflisting#lid
.For example:
This approach has no real limit on the number of watching or listing relationships.
You can then query all items for a given user simply by issuing a query for
pk=user#42
and that will yield the user and all associated watching and listing items (pagination notwithstanding). You can query all listings for a given user withpk=user#42
andsk begins_with("listing#")
.Note that this will increase the table size because of the additional "user", "watching", and "listing" prefixes on attribute values so you may want to consider abbreviating those.
To quote Alex DeBrie:
DynamoDB中对象的限制为
400 kb
,请参见 DynamoDB配额。对于较大的属性值,AWS建议在GZIP等格式中压缩属性,并将其存储在DynamoDB中。其他选项是将项目以JSON格式存储在S3中,并将该文件的密钥存储在DynamoDB中。
请参阅:用于存储大型物品和属性的最佳实践
大概是第三个选项是以某种方式将您的数组分开,并在DynamoDB中创建多个条目。或尝试为单独的属性创建单独的表,显然,如果例如
listings
数组的大小大于对象限制本身,则不会解决问题。The limit of an object in DynamoDB is
400 KB
, see DynamoDB Quotas.For larger attribute values AWS suggests compressing of the attribute in formats such as GZIP, and store it in binary in DynamoDB. Other option would be to store the item in JSON format in S3 and store the key of this file in DynamoDB.
See: Best Practices for Storing Large Items and Attributes
Probably, a third option would be to split your array somehow, and create multiple entries in DynamoDB. Or try to create separate tables for separate attributes, obviously this wont solve the issue if for example
Listings
array's size is larger than the object limit itself.DynamoDB中的表格,表中的每个行都是对象。
行中的项目以JSON对象格式查看。
该行无法支持JSON数组。
分成2个表。表A中的存储列表和表B中的另一个。设计主键并正确对键进行排序,以便可以识别记录属于特定用户。
The table in dynamoDB, every row in the table is object.
The item in a row view it in json object format.
The row cannot support json array.
Split into 2 table. Store listing in table A and another in table B. Design the primary key and sort key correctly so that it can identified the records belong to particular user.