正在从 table 发电机数据库中获取所有数据

Fetching all data from table dynamo DB

我想在我的前端文件 order.js.

中显示来自 table“订单”的所有数据

我在 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 中没有select all 操作可用。

作为解决方法,您可以向数据项添加一个具有常量值的 属性 并存储它。在 属性 上创建全局二级索引,您可以将其用作 select 所有可用记录的关键条件表达式。但请注意,这将被视为 anti-pattern.