amazon-dynamodb - 在 DynamoDB 中查询索引导致主键错误
问题描述
我发现很难在表上查询 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',
解决方案
推荐阅读
- python - 通过匹配 Python 中的某些单词为新创建的列分配值
- python - 带有样式的 Python Plotly 雷达图
- android - 如何创建 google 登录并使用 google 帐户显示内容?
- reactjs - 如何设置 snowpack/webpack url 以正确构建 React 应用程序,使其在开发和生产模式下都可以工作?
- r - 将列添加到具有基于先前行的多个条件和公式的数据框
- php - 将多维 PHP 数组转换为两个不同的数组
- jquery - 触发弹出窗口以在移动设备中打开
- javascript - 执行函数后如何取消选择所有 Material UI 表行
- json - 为什么即使没有调用任何动作,Spark 也会读取数据?
- python - 在 Python 中的基于文本的 RPG 中创建一个简单的经验点获取和升级系统