查询全局二级索引:'MissingRequiredParameter:缺少必需的键

问题描述 投票:0回答:1

我有一个像这样的DynamoDB表定义:

{
"pk": {
  "S": "00000000-0000-0000-0000-000000000001"
},
"sk": {
  "S": "00000000-0000-0000-0000-000000000001"
},
"year": {
  "N": "2019"
}
"index": {
  "N": "987654321"
}
}

其中“ pk”是分区密钥。而“ sk”是排序键。如果您想知道为什么pk和sk都具有相同的值:Adjacency List Design Pattern

我已经在属性“索引”上创建了全局二级索引。它的投影都是pk和sk键。

enter image description here

现在,following the documentation我正在这样查询我的GSI:

        const params = {
                TableName: 'my_table_name',
                IndexName: 'my_index_name',
                KeyConditionExpression: "index = :v_index",
                ExpressionAttributeValues: {
                    ":v_index": {"N": 987654321}
                },
                ProjectionExpression: "pk",
                ScanIndexForward: false
            };

我收到以下错误消息:'MissingRequiredParameter:缺少参数中的必需键\'Key \'\ n

以防万一,我在Lambda中使用Node.js 8.10

amazon-web-services aws-lambda amazon-dynamodb aws-sdk dynamodb-queries
1个回答
0
投票

通常,GSI可以具有相同GSI主键+辅助键组合的多个条目。结果,您无法使用getItem()调用来检索对象。针对GSI的查询必须为scanquery

这在Amazon关于working with GSIs的文档的前几行中已提到

© www.soinside.com 2019 - 2024. All rights reserved.