Node.js DynamoDb如何查询全局二级索引?
我已经创建了一个如下表,在Em处有一个全局二级索引(表示电子邮件) 从node.js SDK中,我尝试使用EmailIndex查询表,如下所示:Node.js DynamoDb如何查询全局二级索引?,node.js,amazon-dynamodb,Node.js,Amazon Dynamodb,我已经创建了一个如下表,在Em处有一个全局二级索引(表示电子邮件) 从node.js SDK中,我尝试使用EmailIndex查询表,如下所示: const params = { TableName: 'Users', IndexName: 'EmailIndex', Key: { Em: email } } try { const data = await docClient.get(params).promise() return data } catch (
const params = {
TableName: 'Users',
IndexName: 'EmailIndex',
Key: {
Em: email
}
}
try {
const data = await docClient.get(params).promise()
return data
} catch (error) {
throw error
}
{
"message": "The number of conditions on the keys is invalid",
"code": "ValidationException",
"time": "2018-07-02T10:33:13.313Z",
"requestId": "edc5f2e0-3c2b-4354-9342-4a96c74988a6",
"statusCode": 400,
"retryable": false,
"retryDelay": 17.366914444025173
}
我得到的答复如下:
const params = {
TableName: 'Users',
IndexName: 'EmailIndex',
Key: {
Em: email
}
}
try {
const data = await docClient.get(params).promise()
return data
} catch (error) {
throw error
}
{
"message": "The number of conditions on the keys is invalid",
"code": "ValidationException",
"time": "2018-07-02T10:33:13.313Z",
"requestId": "edc5f2e0-3c2b-4354-9342-4a96c74988a6",
"statusCode": 400,
"retryable": false,
"retryDelay": 17.366914444025173
}
我正在尝试从电子邮件地址获取数据。我做错了什么?您需要对辅助索引运行查询,而不是从表中读取的项
var email = "JoeBloggs@hotmail.com";
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName : "Users",
IndexName : "EmailIndex",
KeyConditionExpression: "#email = :v_email",
ExpressionAttributeNames:{
"#email": "Em"
},
ExpressionAttributeValues: {
":v_email": email
}
};
docClient.query(params, function(err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded.");
data.Items.forEach(function(item) {
console.log(" -", item.Em + ": " + item.Ai);
});
}
查询数据-
索引-谢谢,我是一个关于它的idot,IndexName记录在哪里?到处都找不到。。。谢谢@vincent关于IndexName的一些信息可以在DynamoDB的云形成文档中找到