根据文档,我正在使用这些参数在 DynamoDB 中创建一个表和 GSI:
configId
是表的主键,我使用 publisherId
作为 GSI 的主键。 (为简洁起见,我删除了一些不必要的配置参数)
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',
}
]
}
]
};
我正在使用这个查询这个表:
{ TableName: 'Configs',
IndexName: 'publisher_index',
KeyConditionExpression: 'publisherId = :pub_id',
ExpressionAttributeValues: { ':pub_id': { S: '700' } } }
但我不断收到错误:
“ValidationException:一个或多个参数值无效:条件参数类型与架构类型不匹配”
In the docs it specifies that the primary KeyType
can either be HASH
or RANGE
, and that you set the AttributeType
in the AttributeDefinitions
字段。我正在发送 publisherId
作为 String
,不确定我在这里缺少什么。
问题是我创建表的方式,还是我查询的方式?谢谢
原文由 Stelios Savva 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试从这里更改
ExpressionAttributeValues
至
从
{ ':pub_id': { S: '700' } }
到{ ':pub_id': '700'}
。我遇到了同样的问题,为此我花了 2 天时间。官方文档中的误导。