Node.js-仅来自AWS DynamoDB的小型项目的Comapring项目

时间:2016-06-23 07:04:57

标签: android amazon-web-services aws-lambda

我希望通过Lambda获取AWS DynamoDB中的项目,满足条件:

if (typeof event.keyWord != "undefined") { 

                var str = event.keyWord;
                str = str.toLowerCase();
                params.ExpressionAttributeValues[":keyWord"] = {"S": str};

                params.FilterExpression = "contains (#nm, :keyWord)";
                }

我从我的Android应用程序发送字符串(keyWord),然后在其上调用toLowerCase函数并将其与来自DB的#nm进行比较。我的问题是,在比较它们之前,如何在#nm上调用类似的函数(toLowerCase)?我的整个代码:

var AWS = require('aws-sdk');
var db = new AWS.DynamoDB();

exports.handler = function(event, context) {


    var params = {
        TableName: "Events", //"StreamsLambdaTable",
       // ProjectionExpression: "locationLat, locationLon",
        ProjectionExpression: "ID, description, endDate, imagePath, locationLat, locationLon, #nm, #tp" //specifies the attributes you want in the scan result.
        ExpressionAttributeNames: {
            "#nm": "name",
            "#tp": "type",
        },
        ExpressionAttributeValues: {
             ":lower_lon": {"N": event.low_lon},
             ":higher_lon": {"N": event.high_lon}, 
             ":lower_lat": {"N": event.low_lat},
             ":higher_lat": {"N": event.high_lat}
        }
    };


     if (typeof event.keyWord != "undefined") { 

                var str = event.keyWord;
                str = str.toLowerCase();
                params.ExpressionAttributeValues[":keyWord"] = {"S": str};

                params.FilterExpression = params.FilterExpression + " and contains (#nm, :keyWord)";
                }

  db.scan(params, function(err, data) {
    if (err) {
      console.log(err); // an error occurred
      } 
    else {

        data.Items.forEach(function(record) {
            console.log(
                record.name.S + "");
        });


        context.succeed(data.Items); // data.Items


      }
  });
};

0 个答案:

没有答案