I am learning DynamoDB and have difficulties understanding where to perform a reduction on data once a DynamoDB query has provided the results and where in the code it would go.
I would like to sum up the running_time_secs.
async function scanForResults () {
try {
var params = {
TableName: "Movies",
ProjectionExpression: "#yr, title, info.rating, info.running_time_secs, info.genres",
FilterExpression: "#yr between :start_yr and :end_yr",
ExpressionAttributeNames: {
"#yr": "year",
},
ExpressionAttributeValues: {
":start_yr": 1950,
":end_yr": 1985,
}
};
var result = await docClient.scan(params).promise()
console.log(JSON.stringify(result))
//const total = result.reduce((sum, result) => sum + result.info.running_time_secs, 0);
} catch (error) {
console.error(error);
}
}
scanForResults();
Thanks for any help.