To fetch/scan all items from AWS dynamodb using Node.js, we use the scan
method.
For instance, we write
const scanTable = async (tableName) => {
const params = {
TableName: tableName,
};
const scanResults = [];
const items;
do {
items = await documentClient.scan(params).promise();
items.Items.forEach((item) => scanResults.push(item));
params.ExclusiveStartKey = items.LastEvaluatedKey;
} while (typeof items.LastEvaluatedKey !== "undefined");
return scanResults;
};
to call scan
to scan the database.
We call promise
to return a promise.
And we use await
to get the results.
We use items.Items
to get the items returned.