gpt4 book ai didi

javascript - 具有多个条件的 Dynamodb filterExpression 不起作用

转载 作者:行者123 更新时间:2023-12-01 00:13:58 27 4
gpt4 key购买 nike

我在nodejs中有一个dynamodb查询,如下所示。 我有一条匹配的记录,但它没有返回任何值。有解决问题的想法吗?

const docClient = new AWS.DynamoDB.DocumentClient({ region: "ap-south-1" });
var userParams = {
TableName: "aa-users",
FilterExpression: '#email = :emailval AND #postProfileOTP = :otpval',
ExpressionAttributeNames: {
"#email": "email",
"#postProfileOTP": "postProfileOTP"
},
ExpressionAttributeValues: {
":emailval": email,
":otpval": otp
}
};
docClient.scan(userParams, function (err, data) {
console.log(data.Count) // not getting the result count
if(data.Count > 0){
res.status(200).json({ "status": 1, "data": data.Items })
}
})

相反,我收到如下错误:

2020-01-24T11:56:20.554Z ee0fd306-6bd5-4cf0-957e-732b08c6b0e3 ERROR Uncaught Exception { "errorType": "TypeError", "errorMessage": "Cannot read property 'Count' of null", "code": "TypeError", "message": "Cannot read property 'Count' of null", "time": "2020-01-24T11:56:20.554Z", "stack": [ "TypeError: Cannot read property 'Count' of null", " at Response. (/var/task/handler.js:351:18)", " at Request. (/var/task/node_modules/aws-sdk/lib/request.js:364:18)", " at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)", " at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)", " at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:683:14)", " at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)", " at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)", " at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10", " at Request. (/var/task/node_modules/aws-sdk/lib/request.js:38:9)", " at Request. (/var/task/node_modules/aws-sdk/lib/request.js:685:12)" ] }

最佳答案

看起来 AWS 返回的是错误而不是结果/数据。当您收到第一个参数为“err”参数的回调时,您应该始终在继续之前检查是否未设置该参数。例如:

if (err) {
console.error(err)
// recover in some way, or kill process
process.exit(1)
}

通过执行此操作,从 AWS 返回的错误将记录到控制台,您将更好地了解出了什么问题。

关于javascript - 具有多个条件的 Dynamodb filterExpression 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59895989/

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