1
我最近开始学习DynamoDB和创建表“评论”具有以下属性(与DynamoDB类型一起):主键和GSI设计在DynamoDB
productId - String
username - String
feedbackText - String
lastModifiedDate - Number (I'm storing the UNIX timestamp)
createdDate - Number
active - Number (0/1 value, 1 for all records by default)
以下是我所期望的查询对这个表运行:
1. Get all reviews for a 'productId'
2. Get all reviews submitted by a 'username' (sorted asc/desc by lastModifiedDate)
3. Get N most recent reviews across products and users (using lastModifiedDate)
为了能够运行这些查询我创建的“评论”表中的下列
现在:
1. A Primary Key with 'productId' as the Hash Key and 'username' as the Range Key
2. A GSI with 'username' as the Hash Key and 'lastModifiedDate' as the Range Key
3. A GSI with 'active' as the Hash Key and 'lastModifiedDate' as the Range Key
最后一个索引有点瑕疵,因为我只在表中引入了'active'属性,因此所有记录的值都可以是'1',我可以将它用作GSI的Hash Key。
我的问题很简单。我已经阅读了一些关于DynamoDB的内容,这是我能想到的最好的设计。我想问问是否有更好的主键/索引设计,我可以在这里使用。如果在DynamoDB中有一个概念,我可能错过了这个特定用例可能会有所帮助。谢谢!