首页 文章

订单导致DynamoDB扫描

提问于
浏览
2

在将数据返回给用户之前,是否可以在scanning一个DynamoDB表中订购结果?

SQL 中,可以运行类似 SELECT * FROM posts ORDER BY creationDate DESC 的查询 . 是否可以使用scan(或者query,但我认为这不会起作用,因为我不知道哈希键值) AWS DynamoDB

虽然可以从数据库中获取所有结果,然后对它们进行排序,但我希望有很多帖子 . 如果有很多帖子,则需要花费很多时间,因为我想只加载一定数量的帖子,直到用户决定加载更多 .

有没有办法按 range keylocal or global secondary index 对结果进行排序?

我试图找到一个黑客来解决这个事实,即似乎没有办法订购结果,而不是寻找这样的东西:

AWSDynamoDBScanInput.order = NSSortDescriptor(key: "creationDate", ascending: true)

除非它存在,尽管从我看来它似乎似乎不可能 .

看起来默认情况下结果是按哈希键排序的,所以,我想将哈希键设置为项目创建日期,使用范围键的UID,但AWS DynamoDB documentation似乎警告不要这样做:

将哈希键设置为创建日期:

var creationDate: Int = Int(NSDate().timeIntervalSince1970)

和随机UID的范围键工作来排序帖子?

scanning DynamoDB表时是否可以订购结果?将创建日期(作为 Int )设置为哈希键,将随机UID设置为范围键吗?是否有任何(更好的)黑客可以用来解决 DynamoDB 没有排序功能的事实?

1 回答

  • 1

    唯一的方法是查询索引 . 您可能需要添加一个全局二级索引,以便're trying to do but it is probably not a good design. The reason why it needs to be an Index is that Dynamo stores every item in a Hash in order of the Range. So if you had a Hash that you knew (maybe add a property to every document that has the same value and make that the Hash Key) then it would sort by Range (which you'为您创建感兴趣的时间戳 . 然后它将是有序的 . 你可能会遇到这方面的问题,但如果像你说的那样,你正在寻找一个黑客,这应该有用 .

相关问题