【发布时间】:2017-09-29 16:17:46
【问题描述】:
我刚刚开始使用 DynamoDB 并设置了一个“帐户”表。
我已经设置了二级索引,这样我就可以查询 api 用户和用户密钥。 这些值都不是主键,因为它们都是易变的并且可以更改。
表格是用
构建的TableName: "Accounts",
KeySchema: [
{ AttributeName: "id", KeyType: "HASH" },
{ AttributeName: "email", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: "email", AttributeType: "S" }
]
索引是
TableName: 'Accounts',
AttributeDefinitions: [
{AttributeName: 'name', AttributeType: 'S'},
{AttributeName: 'apiKey', AttributeType: 'S'}
],
GlobalSecondaryIndexUpdates: [
{
Create: {
IndexName: "ApiAccounts",
ProvisionedThroughput: {
ReadCapacityUnits: 1, WriteCapacityUnits: 1
},
KeySchema: [
{AttributeName: 'name', KeyType: "HASH"},
{AttributeName: 'apiKey', KeyType: "STRING"}
],
Projection: {
ProjectionType: "KEYS_ONLY"
},
我现在正在尝试通过查询ApiAccounts 索引来获取用户帐户。
我在努力
dynamoClient.get({
TableName: 'Accounts',
IndexName: 'ApiAccounts',
Key: {
name: nameKeyArray[0],
apiKey: nameKeyArray[1]
}, callback)
但是我收到了一个错误One of the required keys was not given a value,这让我相信我无法在索引上“获取”?或者我没有正确引用索引。有人可以为我澄清吗?
名称和 API 密钥是唯一的,所以我想尽可能避免查询或扫描
【问题讨论】:
标签: amazon-dynamodb