0

AWS Documentation Sucks, I can't seem to get an idea of how to "scan" DynamoDb with two or more where conditions, in NodeJS ?

Here's my code

const AWS = require("aws-sdk");
let documentClient = new AWS.DynamoDB.DocumentClient();


module.exports.RetryIncompleteCSV = async (event, context, callback) => {
  console.log('In RetryIncompleteCSV');
  const cmpId = event.queryStringParameters.campaign;
  console.log('cmpId = ', cmpId);

  var params = {
    TableName : 'processed_csv_developments',
    FilterExpression : 'campaignId = :campaignId',
    ExpressionAttributeValues : {':campaignId' : cmpId}
  };

  let incompleteCsvData = await scanIncompleteProcessedCsv(params);

  console.log('incompleteCsvData = ', incompleteCsvData);
}

async function scanIncompleteProcessedCsv(params) {  // get method fetch data from dynamodb  
console.log(params)
  const queryExecute = await documentClient.scan(params, function(err, data) {
     if (err) console.log(err);
     else console.log(data);
     console.log('queryExecute=',queryExecute)
  });
} 

I need scan to filter out data, based on following two conditions:

  1. campaignId must be equal to the campaignId that I get from query params.
  2. isComplete should be equal to false (Boolean)

The code written above neither give any error nor a success message. Attaching the cloudwatch logs screenshot below : CloudWatch Logs

What am I missing. I looked at a lot of questions and tutorials, but nothing worked for me. Please Help!

1
  • Might I suggest you add a return statement to your scanIncompleteProcessedCsv() function? Commented Dec 17, 2020 at 20:28

1 Answer 1

1

scanIncompleteProcessedCsv should return a promise. Now it returns void, this mean RetryIncompleteCSV function will finish before a querying to dynamoDB complete.

async function scanIncompleteProcessedCsv(params) {  // get method fetch data from dynamodb  
console.log(params)
  return await documentClient.scan(params).promise();
} 

About multiple conditions, I found to many documents about that, just try:

  var params = {
    TableName : 'processed_csv_developments',
    FilterExpression : 'campaignId = :campaignId AND isComplete = false',
    ExpressionAttributeValues : {':campaignId' : cmpId}
  };

Ref: Link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.