我发现在桌面上查询GSI很困难。下面的代码示例导致与主键相关的键错误,尽管我正在使用索引。
表格定义:
TableName : config.user_table,
KeySchema: [
{ AttributeName: "user", KeyType: "HASH"}
],
AttributeDefinitions: [
{ AttributeName: "user", AttributeType: "S" },
{ AttributeName: "activation_code", AttributeType: "S" },
],
GlobalSecondaryIndexes: [
{
IndexName: "activation_code_index",
KeySchema: [
{AttributeName: "activation_code", KeyType: "HASH"}
],
Projection: {
ProjectionType: "ALL"
},
ProvisionedThroughput: {
"ReadCapacityUnits": 1,"WriteCapacityUnits": 1
}
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
查询定义:
var params = {
TableName: config.user_table,
IndexName: "activation_code_index",
KeyConditionExpression: "activation_code = :code",
ExpressionAttributeValues: {
":code": code
}
};
return dcl.query(params).promise();
错误:
message: 'One or more parameter values were invalid: Missing the key user in the item',
code: 'ValidationException',