4

現在、範囲値は によって取得される BigDecimalTime.now.to_fであり、次のようにユーザーのすべてのドキュメントを取得したいと考えています。

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

docs範囲値の降順で並べられます。

4

1 に答える 1

3

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.

myuser_idはハッシュ値であるため、クエリを次のように修正できました。

docs = table.items.query(:hash_value => user_id, :scan_index_forward => false).select.map {|i| i.attributes}
于 2012-03-07T21:29:58.997 に答える