我使用 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' });
> }
此 api 中出现错误,未找到请求的资源
ResourceNotFoundException 告诉您,对于您配置的帐户/区域,它无法找到名为
carrier
的表。