gpt4 book ai didi

node.js - 使用 NodeJs 的 AWS DynamoDB 查询

转载 作者:行者123 更新时间:2023-12-02 02:37:50 25 4
gpt4 key购买 nike

我有一个 AWS DynamoDB 表,其中包含列电子邮件(分区键)和密码。我想运行一个查询,并结合提供电子邮件和密码来获取匹配记录。
我正在使用 JavaScript(NodeJs) AWS SDK 进行集成。
但是我在执行查询时面临一些挑战,下面是我正在使用的代码块-

var params = {
TableName : "tblUsers",
KeyConditionExpression : 'email = :emailValue',
FilterExpression : '#password= :passwordValue',
ExpressionAttributeNames : {
'#password' : 'password'
},
ExpressionAttributeValues : {
':emailValue' : email,
':passwordValue' : password
}
};

dynamodb.query(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
//console.log("Success", data.Items);
data.Items.forEach(function(element, index, array) {
console.log(element);
});
}
});

以下是我收到的错误 -
Error MultipleValidationErrors: There were 8 validation errors:
* InvalidParameterType: Expected params.ExpressionAttributeValues[':value'] to be a structure
* UnexpectedParameter: Unexpected key '0' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '1' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '2' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '3' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '4' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '5' found in params.ExpressionAttributeValues[':value']
* UnexpectedParameter: Unexpected key '6' found in params.ExpressionAttributeValues[':value']

Reference Document

最佳答案

尝试这样的事情:

const AWS = require("aws-sdk");

const documentClient = new AWS.DynamoDB.DocumentClient({ region: "us-west-2" });

const query = async () => {
const response = await documentClient
.query({
TableName: "tblUsers",
ExpressionAttributeNames: {
"#password": "password",
"#email": "email"
},
ExpressionAttributeValues: {
":emailValue": "email",
":passwordValue": "password",
},
FilterExpression: "#password = :passwordValue",
KeyConditionExpression: "#email = :emailValue",
})
.promise();

console.log(`Query response: ${JSON.stringify(response, null, 2)}`);
};

query().catch((error) => console.error(JSON.stringify(error, null, 2)));

关于node.js - 使用 NodeJs 的 AWS DynamoDB 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64053683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com