如何使用AWS SDK在DynamoDB中订购



目前,我的范围值是Time.now.to_f获得的BigDecimal,我想检索用户的所有文档,如下所示:

table = dynamo_db.tables['some_table']
table.load_schema
docs = table.items.where(:user_id => user_id).select.map {|i| i.attributes}

docs在值递减的范围内排序。

在深入研究SDK源代码后,我能够为方法AWS::DynamoDB::ItemCollection#query 找到这个有用的小金块

  # @option [Boolean] :scan_index_forward (true) Specifies which
  #   order records will be returned.  Defaults to returning them
  #   in ascending range key order.  Pass false to reverse this.

由于我的user_id是散列值,我可以将查询修改为:

docs = table.items.query(:hash_value => user_id, :scan_index_forward => false).select.map {|i| i.attributes}

最新更新