【问题标题】:DynamoDB query with lambda (node.js) FilterExpression using containsDynamoDB 查询与 lambda (node.js) FilterExpression 使用包含
【发布时间】:2017-07-19 14:21:12
【问题描述】:

Here is the table structure. In posts column it is a list of strings
所以我一直在阅读并尝试将 filterExpression 与“包含”一起使用。 node.js 中所说的文档只需要使用 a CONTAINS b 其中 a 可以是一个列表,而 b 对我来说是一个字符串寻找。

var db = new doc.DynamoDB();

var params = {
    TableName: "WIT_Search",
    KeyConditionExpression: "#type = :tag and #key between :start AND :end",
    FilterExpression: "#tag contains :post",
    ExpressionAttributeNames: {
        "#type": "type",
        "#tag": "posts",
        "#key": "key",
    },
    ExpressionAttributeValues: {
        ":tag": "tag",
         ":start": tag+"_",
         ":end": tag+"_999",
         ":post": postID
    }
};

console.log(params);

db.query(params, function(err, data) {
    if (err) {
        console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
    } else {
        console.log("Query succeeded.");
        console.log('Count =',data.Items.length);

        if (data.Items.length > 0){
            console.log("post exists in tag");
        }else{
            console.log("post doesnt exist in tag");
        }
    }
});


每当我进行测试时,它都会给我这个信息:

  Unable to query. Error: {
      "message": "Invalid FilterExpression: Syntax error; token: \"contains\", near: \"#tag contains (\"",
      "code": "ValidationException",
    }

AWS 控制台上的奇怪之处在于它可以正常工作,只是在带有 node.js 的 lambda 中使用它会给出这个错误。

【问题讨论】:

    标签: javascript node.js lambda amazon-dynamodb


    【解决方案1】:

    这是正确的语法。

    FilterExpression : 'contains (#tag, :post)'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 2016-05-20
      • 2017-10-25
      相关资源
      最近更新 更多