DynamoDB中的一对多架构

时间:2018-03-23 13:48:58

标签: amazon-dynamodb

我目前正在为以下用例设计dynamo DB模式:

公司可以拥有多个频道,然后对于每个频道,我都有多个频道卡。

我正在考虑使用以下表格:

频道表:

Partition Key: CompanyId
Sort Key: Combination of Time Stamp and deleted or not

现在获得公司的频道后,我需要获取其频道卡,为此,我想在ChannelCard上使用Table Schema。

ChannelCard表:

Partition Key: channelId
Sort Key: Combination of Time Stamp and deleted or not

现在要获取公司的频道卡,我需要执行以下操作:

 1. First query the channels for the company using partition key (1 query)
 2. Getting channel cards for each channel (number of channels query)

所以在这种情况下,我们会进行很多查询,在这种情况下,我们可以查询更少数量的查询吗?

欢迎任何有关修改数据库表或如何查询数据库的建议。

1 个答案:

答案 0 :(得分:1)

你也可以

频道表

Partition Key: CompanyId
Sort Key: Deleted+timestamp

频道卡表

Partition Key: CompanyId
Sort Key: Deleted+ChannelCardTimeStamp

GSI #1:
Partition Key: ChannelId
Sort Key: Deleted+ChannelCardTimeStamp

通过这种方式,您可以查询任何指定公司的最新通道卡,也可以查询任何频道的最新通道卡。

相关问题