我刚开始使用DynamoDB并设置了“帐户”表。使用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密钥是唯一的,所以我觉得我想避免的查询或扫描如果可能的话
感谢您的澄清,我是全部结束http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.JavaScript.html - 我假设查询将最适合我的用例和性能? – pedalpete
@pedalpete是的,但请注意,查询索引时可能会有重复记录返回,因为索引的哈希和范围键不是唯一的,这与Table不同。 –