在dynamodb Local中查询全局二级索引 [英] Querying a Global Secondary Index in dynamodb Local

查看:113
本文介绍了在dynamodb Local中查询全局二级索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,我使用以下参数在DynamoDB中创建表和GSI:

I am creating a table and GSI in DynamoDB, using these parameters, as per the documentation:

configId 是表的主键,我使用 publisherId 作为GSI的主键。 (为简便起见,我删除了一些不必要的配置参数)

configId is the primary key of the table, and I am using the publisherId as the primary key for the GSI. (I've removed some unnecessary configuration parameters for brevity)

var params = {
    TableName: 'Configs',
    KeySchema: [ 
        {
            AttributeName: 'configId',
            KeyType: 'HASH',
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'configId',
            AttributeType: 'S',
        },
        {
            AttributeName: 'publisherId',
            AttributeType: 'S',
        }
    ],
    GlobalSecondaryIndexes: [ 
        { 
            IndexName: 'publisher_index', 
            KeySchema: [
                {
                    AttributeName: 'publisherId',
                    KeyType: 'HASH',
                }
            ]
        }
    ]
};

我正在使用以下查询表:

I am querying this table using this:

{ TableName: 'Configs',
  IndexName: 'publisher_index',
  KeyConditionExpression: 'publisherId = :pub_id',
  ExpressionAttributeValues: { ':pub_id': { S: '700' } } }

但我一直收到错误消息:

but I keep getting the error:


ValidationException:一个或多个参数值无效:条件参数类型与模式类型不匹配

"ValidationException: One or more parameter values were invalid: Condition parameter type does not match schema type"

在文档中指定主 KeyType 可以为 HASH RANGE ,并且您在 AttributeDefinitions AttributeType $ c>字段。我将 publisherId 发送为 String ,不确定我在这里缺少什么。

In the docs it specifies that the primary KeyType can either be HASH or RANGE, and that you set the AttributeType in the AttributeDefinitions field. I am sending the publisherId as String, not sure what I am missing here.

问题在于我创建表的方式还是我查询的方式?
谢谢

Is the issue in the way I am creating the table, or the way I am querying? Thanks

推荐答案

尝试更改此内容

{ 
 TableName: 'Configs',
 IndexName: 'publisher_index',
 KeyConditionExpression: 'publisherId = :pub_id',
 ExpressionAttributeValues: { ':pub_id': { S: '700' } } 
}



in this

{ 
 TableName: 'Configs',
 IndexName: 'publisher_index',
 KeyConditionExpression: 'publisherId = :pub_id',
 ExpressionAttributeValues: { ':pub_id': '700'} 
}

{':pub_id':{S:'700'}} {':pub_id':'700' }

我遇到了同样的问题,为此花了2天的时间。官方文件具有误导性。

I had the same problem and I spent 2 days for this. The official documentation in misleading.

这篇关于在dynamodb Local中查询全局二级索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆