Amazon dynamodb 在DynamoDB中查询索引会导致主键错误
我发现在桌子上查询GSI很困难。下面的代码示例导致与主键相关的键错误,尽管我使用的是索引 表定义:Amazon dynamodb 在DynamoDB中查询索引会导致主键错误,amazon-dynamodb,Amazon Dynamodb,我发现在桌子上查询GSI很困难。下面的代码示例导致与主键相关的键错误,尽管我使用的是索引 表定义: TableName : config.user_table, KeySchema: [ { AttributeName: "user", KeyType: "HASH"} ], AttributeDefinitions: [ { AttributeName: "user", AttributeType: "S" }, { AttributeNam
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();
查询定义:
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',
尝试在代码中的
activation\u code\u index
周围使用双引号。JSON的标准要求双引号,而不是单引号。@JeffreyPhillipsFreeman将单引号改为双引号,但仍然存在相同的问题。唯一让我感到不寻常的是,在表定义中,在二级索引之前没有“CREATE:”标记。你确定索引是真的吗created@JeffreyPhillipsFreeman我可以在dynamodbui中看到索引。我还可以在UI中查询索引,问题似乎是通过aws-sdk进行查询。对不起,我当时不知所措:(