0

我有一个包含“目录”、“集合”等实体的应用程序。我想使用标记对实体之间的关系进行建模。例如,我可能有一个销售目录和一个销售集合。我会知道这两个实体是连接的,因为它们都有相同的标签:“销售”。

以下是我需要做的查询:

1)获取某种类型的所有实体,即目录

2) 通过 ID 获取实体

3) 获取所有带有特定标签的实体

4)通过某个标签查询实体列表,并检索与该实体关联的其余标签。

我想知道如何在 Dynamo DB 中建模

我首先认为我可以这样做:

PK = entityType_id (e.g. catalog_1)
SK = Tag (e.g. sales)

问题是我无法获得某种类型的所有实体。(1)

我想也许我可以这样做:

PK = entityType (e.g. catalog)
SK = id_tag (e.g. 1_sales)

我可以完成:在 SK 上使用 BeginsWith 和 EndsWith 的 1,2above 和 3 使用类型标签为 PK 但无法完成的 GSI 4。

将来我还希望能够按标签类型进行查询。我看不出在亚马逊推荐的一张表中或不使用 RDBMS 的情况下如何实现所有这些。

我真的很感激我能得到的任何意见或方向。

谢谢!

4

1 回答 1

2

您可以将其用作您的架构

|    pk   |     sk               |     GSI1 PK          | 
|  uid1   |    metadata          |                      |   tags:["sales","purchase", "borrow"] | entityType:["catalogs"]
|  uid1   |entityType#catalogs   | entityType#catalogs
|  uid1   |    tag#sales         | tag#sales
|  uid1   |    tag#purchase      | tag#purchase
|  uid1   |    tag#borrow        | tag#borrow
|  uid2   |entityType#collection | entityType#collection
|  uid2   |    tag#borrow        | tag#borrow
|  uid2   |    metadata          |                      |   tags: ["borrow"] | entityType:["collection"]

其中 PK 是 GSI1 的 SK(GSI1:全球二级索引)

这将解决用例,例如

  1. 获取所有销售实体

    Select* where PK=entityType#sales in table GSI1

  2. 通过 id 获取实体

    Select * wehere PK=id and SK=metadata

  3. 获取所有带有 Sales 标签的实体

    Select* where PK=tag#sales in table GSI1

  4. 通过特定标签查询实体列表并检索与该实体关联的其余标签。

    Use 3rd query and get all list of uids and then do a get all tags, or duplicate tags data as well in every row.

于 2019-02-03T07:24:05.987 回答