dynamodb unmarshall阵列DynamoDB记录? (SDK V3 JavaScript)
我找不到一种揭开DynamoDB记录阵列的方法吗?我从DynamoDB中的查询中获取了多个项目,并且我无法使用来自数组上的@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)
响应:
[
{
deviceId: {
S: "test1",
},
userId: {
S: "318ecd46-bead-440f-83eb-60345aaa1c40",
},
timestamp: {
S: "2022-06-12",
},
frequency: {
S: "Monthly",
},
},
{
deviceId: {
S: "test2",
},
userId: {
S: "318ecd46-bead-440f-83eb-60345aaa1c40",
},
timestamp: {
S: "2022-06-12",
},
frequency: {
S: "Monthly",
},
},
]
所需响应:
[
{
deviceId: "test1",
userId: "318ecd46-bead-440f-83eb-60345aaa1c40",
timestamp: "2022-06-12",
frequency: "Monthly",
},
{
deviceId: "test2",
userId: "318ecd46-bead-440f-83eb-60345aaa1c40",
timestamp: "2022-06-12",
frequency: "Monthly",
},
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在V3中执行这样的操作:
You can do something like this in v3:
DynamodBdocumentClient
是为了自动删除数据并使其更易于在代码中使用的数据。这将为您提供Dynamo数据作为常规JavaScript对象,如您所期望的。
文档:
DynamoDBDocumentClient
is made to automatically unmarshall your data and make it easier to work with in your code.This will give you the Dynamo data as a regular JavaScript object as you'd expect.
Documentation: https://docs.aws.amazon.com/en_us/AWSJavaScriptSDK/v3/latest/classes/_aws_sdk_lib_dynamodb.dynamodbdocumentclient-1.html