使用 Ruby SDK 的 DynamoDB 查询
DynamoDB query with Ruby SDK
我真的很难使查询正常工作。我正在尝试获取主键 ('keyword') 等于 'compost spoons'.
的所有项目
这是我的一件物品:
{
"keyword": "compost spoons",
"created_at": "2020-08-12T11:31:21+00:00"
}
这是我查询中的参数:
params = {
table_name: "servings",
select: "ALL_ATTRIBUTES",
return_consumed_capacity: "INDEXES",
key_condition_expression: "keyword = :keyword_val",
expression_attribute_values: {
"keyword_val" => "compost spoon"
}
}
它通过的错误:
"ExpressionAttributeValues contains invalid key: Syntax error; key: \"keyword_val\""
要使查询正常工作,参数应该是什么?
架构:
{
"AttributeDefinitions": [
{
"AttributeName": "keyword",
"AttributeType": "S"
},
{
"AttributeName": "created_at",
"AttributeType": "S"
}
],
"TableName": "servings",
"KeySchema": [
{
"AttributeName": "keyword",
"KeyType": "HASH"
},
{
"AttributeName": "created_at",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2020-08-14T10:26:55.528Z",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
"LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableSizeBytes": 168,
"ItemCount": 3,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/servings"
}
您在 expression_attribute_values
中的 keyword_val
前面似乎少了一个冒号。我认为应该是:
params = {
table_name: "servings",
select: "ALL_ATTRIBUTES",
return_consumed_capacity: "INDEXES",
key_condition_expression: "keyword = :keyword_val",
expression_attribute_values: {
":keyword_val" => "compost spoon". // <---- CHANGE IS HERE!!
}
}
我真的很难使查询正常工作。我正在尝试获取主键 ('keyword') 等于 'compost spoons'.
的所有项目这是我的一件物品:
{
"keyword": "compost spoons",
"created_at": "2020-08-12T11:31:21+00:00"
}
这是我查询中的参数:
params = {
table_name: "servings",
select: "ALL_ATTRIBUTES",
return_consumed_capacity: "INDEXES",
key_condition_expression: "keyword = :keyword_val",
expression_attribute_values: {
"keyword_val" => "compost spoon"
}
}
它通过的错误:
"ExpressionAttributeValues contains invalid key: Syntax error; key: \"keyword_val\""
要使查询正常工作,参数应该是什么?
架构:
{
"AttributeDefinitions": [
{
"AttributeName": "keyword",
"AttributeType": "S"
},
{
"AttributeName": "created_at",
"AttributeType": "S"
}
],
"TableName": "servings",
"KeySchema": [
{
"AttributeName": "keyword",
"KeyType": "HASH"
},
{
"AttributeName": "created_at",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2020-08-14T10:26:55.528Z",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
"LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableSizeBytes": 168,
"ItemCount": 3,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/servings"
}
您在 expression_attribute_values
中的 keyword_val
前面似乎少了一个冒号。我认为应该是:
params = {
table_name: "servings",
select: "ALL_ATTRIBUTES",
return_consumed_capacity: "INDEXES",
key_condition_expression: "keyword = :keyword_val",
expression_attribute_values: {
":keyword_val" => "compost spoon". // <---- CHANGE IS HERE!!
}
}