簡體   English   中英

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

[英]How to scan AWS DynamoDB with wild card in Nodejs

我在 nodejs 中使用 aws-sdk,我應該用通配符掃描數據庫。

我用aws 開發者指南試過這個:

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}));
            }
        }
    }
})

我已經參考了這個文件

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM