I'm working with AWS DynamoDB and trying to query a table for email addresses. I want to see how many of the same emails exist in the table. But for some reason when I run the function below I get undefined.
let docClient = new AWS.DynamoDB.DocumentClient();
function checkEmail(email) {
var params = {
TableName: "Users",
IndexName: "email",
KeyConditionExpression: "email=:email",
ExpressionAttributeValues: {
":email": email
}
}
var emails = 0;
docClient.query(params, function (err, data) {
if (err) {
return -1;
}
else {
emails = data.ScannedCount;
}
});
return emails;
}
I think it may have to do something with the function finishing before the table is fully queried. But I don't know how I would go about solving this (async/await?).