加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何使用AWS SDK在DynamoDB中订购?

发布时间:2020-12-17 02:17:23 所属栏目:百科 来源:网络整理
导读:目前,我的范围值是Time.now.to_f获得的BigDecimal,我想检索用户的所有文档,如下所示: table = dynamo_db.tables['some_table']table.load_schemadocs = table.items.where(:user_id = user_id).select.map {|i| i.attributes} 文档按范围值降序排序. 解决方
目前,我的范围值是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}

文档按范围值降序排序.

解决方法

在深入研究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}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读