我找不到解组 DynamoDB 记录数组的方法?我从 DynamoDB 中的查询返回多个项目,但无法使用unmarshal来自@aws-sdk/util-dynamodb记录数组的函数。当我迭代记录数组并解组每一条记录时,这可行,但这不是最好的解决方案,因为我要返回大量数据。如何让 DynamoDB 返回多条记录,而无需迭代记录数组来解组每条记录?
代码:
const client = new DynamoDBClient({ region: 'us-east-1' });
const currentDateUTC = moment().utc().format('YYYY-MM-DD');
const command = new QueryCommand({
TableName: 'Device-Data',
IndexName: 'timestamp-index',
KeyConditionExpression: '#timestamp = :timestamp',
ExpressionAttributeNames: { '#timestamp': 'timestamp' },
ExpressionAttributeValues: { ':timestamp': { S: currentDateUTC } },
});
const data = await client.send(command)
Run Code Online (Sandbox Code Playgroud)
回复:
[
{
deviceId: {
S: "test1",
},
userId: {
S: "318ecd46-bead-440f-83eb-60345aaa1c40",
},
timestamp: {
S: "2022-06-12",
},
frequency: {
S: "Monthly",
},
}, …Run Code Online (Sandbox Code Playgroud)