我正在使用“aws-sdk”、“~> 2.6.44”。我有一张activities
表,用于存储用户执行的所有活动。
params = {
table_name: 'activities', # required
key_schema: [ # required
{
attribute_name: 'actor', # required User.1
key_type: 'HASH', # required, accepts HASH, RANGE
},
{
attribute_name: 'created_at', # timestamp
key_type: 'RANGE'
}
],....
我想用用户在过去 1 天执行的所有活动查询此表。看起来AWS 文档站点有 SDK 版本 3 的文档。
tableName = 'activities'
params = {
table_name: tableName,
key_condition_expression: "#user = :actor and #time between :start_time and :end_time",
expression_attribute_names: {
"#user" => 'actor',
"#time" => "created_at"
},
expression_attribute_values: {
actor: 'User.1',
":start_time" => (Time.now - 1.days).to_i,
":end_time" => (Time.now + 1.days).to_i
}
}
DynamodbClient.client.get_item(params)
# Throws: ArgumentError: no such member :key_condition_expression
我尝试使用过滤器表达式:
tableName = 'activities'
params = {
table_name: tableName,
key: {
actor: 'User.1'
},
filter_expression: "created_at BETWEEN (:id1, :id2)",
expression_attribute_values: { ":id1" => (Time.now - 1.days).to_i,":id2" => (Time.now + 1.days).to_i},
projection_expression: "actor"
}
DynamodbClient.client.get_item(params)
# Throws ArgumentError: no such member :filter_expression
使用范围键的范围选项查询 DynamoDB 表的正确方法应该是什么?