2021-12-05

How to do find all or get all in dynamo db in NodeJS

I want to get all the data from a table in Dynamo DB in nodejs, this is my code

const READ = async (payload) => {
  const params = {
    TableName: payload.TableName,
  };

  let scanResults = [];
  let items;
  do {
    items = await dbClient.scan(params).promise();
    items.Items.forEach((item) => scanResults.push(item));
    params.ExclusiveStartKey = items.LastEvaluatedKey;
  } while (typeof items.LastEvaluatedKey != "undefined");

  return scanResults;
};

I implemented this and this is working fine, but our code review tool is flagging red that this is not optimized or causing some memory leak, I just cannot figure out why, I have read somewhere else that scanning API from dynamo DB is not the most efficient way to get all data in node or is there something else that I am missing to optimize this code



from Recent Questions - Stack Overflow https://ift.tt/3dn3Vmy
https://ift.tt/eA8V8J

No comments:

Post a Comment