如何在 Nodejs 中使用通配符扫描 AWS DynamoDB

How to scan AWS DynamoDB with wild card in Nodejs

我在nodejs中使用aws-sdk,我应该用通配符扫描数据库。

我用 aws developer guide 试过了:

var params = {
    TableName: RecipeTable,
    FilterExpression: "#recipe = :recipe",
    ExpressionAttributeNames:{
        "#recipe": "recipe",
    },
    ExpressionAttributeValues: {
        ":recipe": request.params.recipe,
    }
};

我找不到答案。

有人可以帮助我吗?

谢谢。

我找到了答案:使用 contains 关键字。

app.get('/recipe/:recipe', (request, response) => {
    var params = {
        TableName: RecipeTable,
        FilterExpression: "contains(#recipe, :recipe)", // Here!
        ExpressionAttributeNames:{
              "#recipe": "ingredients"
        },
        ExpressionAttributeValues: {
              ":recipe": request.params.recipe
        }
    };

    result = [];
    docClient.scan(params, onScan);

    function onScan(err, data) {
        if (!err) {
            data.Items.forEach((itemdata) => {
                result.push(itemdata);
            });

            if(typeof data.LastEvaluatedKey != "undefined") {
                params.ExclusiveStartKey = data.LastEvaluatedKey;
                docClient.scan(params, onScan);
            } else {
                response.send(JSON.stringify({"result" : result}));
            }
        }
    }
})

我参考了 this document

谢谢。