2015-11-19 58 views
0

我試圖模型3列的 「簡單」 表:DynamoDB 「複合」 鍵索引結構

userId | topicId | views

表應能:

  • 已經重複userId
  • 重複topicId
  • 強制執行userId和的唯一組合

換句話說,存在與userId相關聯的許多topicId「s和views將是遞增的數。

我將如何創建我的索引,如果我需要做下面的查詢:

  • 得到的記錄列表提供userId
  • 獲得和更新一個獨特的記錄提供userId and topicId

回答

0

由於您擁有比userIds更多的topicIds,因此您應該創建以下表格:

散列鍵 - topicId

範圍鍵 - 用戶id

添加一個全局二級索引與:

哈希鍵 - 用戶id

範圍鍵 - topicId

你可以然後使用組合topicId +插入和更新記錄userId並查詢特定用戶標識的主題列表。