【发布时间】:2019-09-26 20:17:32
【问题描述】:
我有一个 AWS DynamoDb 表,
我有 user_id 作为索引或 GSI(user_id-index
),
我也有 product_type 作为索引或 GSI(prod_type-index
)。
我正在尝试使用 KeyConditionExpression 来查询 DynamoDb 表,
但我得到了一个 -
Validation Exception, with message:"Query key condition not supported" and statusCode: 400
ValidationException: Query key condition not supported\n at Request.extractError
我的桌子上有以下物品结构 -
{
"id": "12345f9f-f08c-45ae-986a-f1b5ac712345",
"user_id": 1234,
"prod_type": "OTHER"
}
以下是我的查询表的 NodeJs 代码 -
let AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1'
});
let connection = new AWS.DynamoDB.DocumentClient();
let table = "some_table";
let params = {
IndexName : "user_id-index",
ExpressionAttributeValues: {
":v1": {
N: 1234
},
":v2": {
S: "OTHER"
}
},
ExpressionAttributeNames: {
"#userId": "user_id",
"#prodType": "prod_type"
},
TableName: table,
KeyConditionExpression: "#userId = :v1 and #prodType = :v2"
};
connection.query(params, function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
参考资料 -
Dynamodb query error - Query key condition not supported
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html
【问题讨论】:
标签: node.js amazon-web-services amazon-dynamodb