DynamoDB.DocumentElement 和 Node.JS 的 GSI

GSI with DynamoDB.DocumentElement and Node.JS

我有一个关于 GSI 的问题。对于使用 DynamoDB 的人来说,这个问题很简单 :)

目前,我正在通过创建博客了解 AWS/DynamoDB。所以每个 post 都有一个类别。我遇到了一个大问题,如果我想获得所有 post 的特殊类别。现在我正在使用扫描并包含一个过滤器。

编辑: 要创建模型,我使用 'dynamodb-toolbox'

我听说我可以申请一个 GSI 并通过 GSI 搜索获得所有 post 类别。最大的问题是...我不知道如何创建 GSI,如何在查询宽度 DocumentClient 和 node.js

中使用它

感谢您的帮助!

I do not know how can I create GSI

这是on the documentation, more specifically available here

I got one big problem that if I want to get all posts which got a special category. Now I'm using a scan and contains a filter.

在这种情况下,根据您当前的数据模型,您需要配置一个 GSI,其中 category 是分区键,id 是排序键,您需要配置主key 作为 PK 和 SK 的复合主键,如 here 所述。

这将允许您 query the data by category on that GSI,因为您将类别作为分区键,当您执行查询时,您将命中一个分区。

how can I use it in query width DocumentClient and node.js

我建议你先弄清楚这些,然后让它独立工作 w/o 担心你的编程语言限制。一旦掌握了这一点,您就可以单独担心编程语言的挑战。