Amazon dynamodb 从表dynamo DB获取所有数据
我想在前端文件Amazon dynamodb 从表dynamo DB获取所有数据,amazon-dynamodb,Amazon Dynamodb,我想在前端文件order.js中显示表“orders”中的所有数据 我在我的app.js app.post('/api/myorders', function (req, res) { var params = { TableName: "orders", Select: "ALL_ATTRIBUTES", }; docClient.scan(params, onScan); functi
order.js
中显示表“orders”中的所有数据
我在我的app.js
app.post('/api/myorders', function (req, res) {
var params = {
TableName: "orders",
Select: "ALL_ATTRIBUTES",
};
docClient.scan(params, onScan);
function onScan(err, data) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
res.send({ success: false,message:JSON.stringify(err, null, 2)})
} else {
res.send( {success: true,orders:data.Items})
}
}
});
在我的前端文件order.js
中,我获取的数据如下
const options = {
method: "post",
headers: {
"Accept": "application/json",
"Content-type": "application/json",
'Authentication': user.getHmac('POST', '/api/myorders')
},
};
fetch(process.env.REACT_APP_DB_URI + "/myorders", options)
.then(res => res.json())
.catch(error => {
console.error("Error:", error)
setErrors("There was an error getting orders.")
})
.then(response => {
if (response.success) {
console.log("Success:", response)
}
else {
console.log("Error:", response)
setErrors("There was an error getting order.")
}
});
但是不断地出错
"success":false,"message":"{\n \"message\": \"ExpressionAttributeValues must not be empty\",\n \"code\": \"ValidationException\",\n \"time\": \"2020-08-30T07:53:06.375Z\",\n \"requestId\": \"11OEEP6KPETMRVVCBE2RD03MJFVV4KQNSO5AEMVJF66Q9ASUAAJG\",\n \"statusCode\": 400,\n \"retryable\": false,\n \"retryDelay\": 25.696811530071486\n}"}
请知道如何解决这个问题,在当前的API状态下,你不能这样做。扫描和查询都要求至少执行一个条件。DDB中没有可用的全选操作 作为一种解决方法,您可以将具有常量值的属性添加到数据项并存储它。在该属性上创建全局二级索引时,可以将其用作键条件表达式,以选择所有可用记录。但请注意,这将被视为反模式