繁体   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