使用node.js SDK V3从dynamoDB获取分页数据

问题描述 投票:0回答:1

我使用 dynamoDB 数据库,因为 aws 已使用 JS 的 sdk v3 进行更新 我想更新我的分页 api 通过 page=1 请求,我得到了 LastEvaluatedKey = { MCNo: { N: '456' } } 的数据,并将其传递给 api/test?page=2&lastEvaluatedKey={ MCNo: { N: '456' } }

这个API有错误的是 错误:类型错误:无法读取未定义的属性(读取“0”)

 const page = parseInt(req.query.page, 10) || 1;
  const pageSize = 10;

  const startKey = page === 1 ? undefined : { pageKey: req.query.lastEvaluatedKey };
    console.log(page, startKey,"test one")
  const scanParams = {
    TableName: 'carrier',
    ExclusiveStartKey: startKey,
    Limit: pageSize,
  };

  const scanCommand = new ScanCommand(scanParams);

  const result = await dbV3.send(scanCommand);

  const items = result.Items;

  const response = {
    data: items,
    nextPage: result.LastEvaluatedKey ? `${req.originalUrl}?page=${page + 1}&lastEvaluatedKey=${result.LastEvaluatedKey}` : null,
  };

  res.json(response);

} catch (error) {
  console.error('Error:', error);
  res.status(500).json({ error: 'Internal Server Error' });
> }

node.js pagination amazon-dynamodb dynamodb-queries
1个回答
0
投票

此 api 中出现错误,未找到请求的资源

ResourceNotFoundException 告诉您,对于您配置的帐户/区域,它无法找到名为

carrier
的表。

  • 仔细检查您使用的角色是否适用于正确的帐户。
  • 仔细检查您配置的区域是否正确
  • 仔细检查表是否存在且名称匹配(区分大小写)
© www.soinside.com 2019 - 2024. All rights reserved.