我在创建一个简单的查询请求时遇到了问题。Here它们展示了如何使用全局辅助索引执行查询的示例。现在,在本例中,我只有主键,我想从我的表中进行查询。这是我目前得到的错误:
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“,它对应于二级索引名称。键模式似乎没有这样的attribute。
下面是在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我遗漏了什么?
发布于 2019-06-12 02:45:07
这正在尝试通过名为HashKey的主键进行查询
KeyConditionExpression: 'HashKey = :hkey',但是,您的主键名为id,这正是错误消息所指出的。因此,将该行更改为:
KeyConditionExpression: 'id = :hkey',https://stackoverflow.com/questions/56547026
复制相似问题