amazon-web-services - Dynamodb 按排序顺序扫描

标签 amazon-web-services amazon-dynamodb

嗨,我有一个 dynamodb 表。我希望该服务返回该表中的所有项目,并且顺序是按一个属性排序。

我需要为此创建一个全局二级索引吗?如果是这样的话,哈希键应该是什么,范围键是什么? (请注意,对 gsi 的查询必须在 GSI 的哈希键上指定“EQ”比较器。)

非常感谢!

埃尔本

最佳答案

如果您知道 HashKey,则任何查询都将返回按 Range 键排序的项目。来自 documentation :

Query results are always sorted by the range key. If the data type of the range key is Number, the results are returned in numeric order. Otherwise, the results are returned in order of UTF-8 bytes. By default, the sort order is ascending. To reverse the order, set the ScanIndexForward parameter set to false.

现在,如果您需要退回所有元素,您应该使用扫描。您无法订购扫描结果。

另一个选项是使用 GSI ( example )。在这里,您可以看到 GSI 仅包含 HashKey。我猜结果将按照该键的排序顺序(我还没有在程序中检查这部分!)。

关于amazon-web-services - Dynamodb 按排序顺序扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21794945/

相关文章:

amazon-web-services - 将丢失的数据字段提取到 SageMaker Feature Store 的功能组中

javascript - dynamodb在列表中添加对象到列表中的对象内nodejs

android - 来自 AWS Android SDK 示例应用程序的 DynamoDB 表不在控制台中

amazon-dynamodb - DynamoDB "single table design"能否与微服务架构完美配合?

java - AWS 免费套餐使用

c# - amazon s3 直接从 asp.net 通过 url 上传文件

java - 更改 S3 对象上的元数据(上次修改)

amazon-web-services - 通过 CLI 的 AWS DynamoDB put-item 类型无效(unicode v. dict)

java - DynamoDB 中的动态属性?

php - 亚马逊结帐付款按钮集成