amazon-web-services - 按主键查询dynamodb表
问题描述
我在创建简单查询请求时遇到问题。这里,他们展示了如何使用全局二级索引进行查询的示例。现在在这种情况下,我只有主键,我想从我的表中查询。这是目前我得到的错误:
Query condition missed key schema element: id
这是我目前正在尝试的:
var params = {
TableName : "XactRemodel-7743-DynamoDBImagesTable-8183NQ0UG0Y5",
KeyConditionExpression: 'HashKey = :hkey',
ExpressionAttributeValues: {
':hkey': event.projectId
}
};
documentClient.query(params, function(err, data) {
if (err) {
console.log(err)
} else {
console.log(data);
}
});
我知道在示例中他们使用了与二级索引名称相对应的“indexName”。他们的 Key Schema 似乎没有这样的属性。
这是我的表在 YAML 文件中定义的样子:
DynamoDBImagesTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: true
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: companyId
AttributeType: S
- AttributeName: lastModified
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: companyId-index
KeySchema:
- AttributeName: companyId
KeyType: HASH
- AttributeName: lastModified
KeyType: RANGE
Projection:
ProjectionType: ALL
我错过了什么?
解决方案
这是尝试通过名为的主键查询HashKey
:
KeyConditionExpression: 'HashKey = :hkey',
但是,您的主键被命名id
,这就是错误消息所指出的。所以将该行更改为:
KeyConditionExpression: 'id = :hkey',
推荐阅读
- php - php如何替换文章中的外部链接
- python - 由于“转换”,导入 matplotlib.animation 失败
- python - 为什么这个 oneliner 给我语法错误?
- node.js - 如何在 Nodejs 中将文件从 Web 下载到服务器端并在 ReactJs 中将其发送到客户端?
- r - 运行后测量R中代码块的运行时间
- python - 如何使用 Python 从 TFS REST API 获取信息?
- python-2.7 - 如何拆分字符串的一小部分?
- c# - 反序列化序列化的 json 字符串列表
- javascript - MaxListenersExceededWarning:可能的 EventEmitter 内存泄漏检测
- c# - C# 表达式检查成员/属性是否为空