Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

amazon dynamodb fiter expression return error

iam created a table in amazon dynamoDB using web console. this is my table structure after adding some data.

timestamp | userid | text

101 | manaf | haaaai

102 | manaf | hello

I need to get the data between two res limits.

this is my code in js.

var AWS = require("aws-sdk");

AWS.config.update({
  region: "regionName",
});

var docClient = new AWS.DynamoDB.DocumentClient()
var table = "testTable";
var params = {
    TableName: table,
    FilterExpression :['userid = :id','res >= :val1','res <= :val2'],
    ExpressionAttributeValues : {':id' : 'manaf','res':101, 'res':102} 
};

docClient.scan(params, function(err, data) {
   if (err) console.log(err);
   else console.log(data);
});

But i got error like this.

{ [InvalidParameterType: Expected params.FilterExpression to be a string]
  message: 'Expected params.FilterExpression to be a string',
  code: 'InvalidParameterType',
  time: Thu May 19 2016 17:24:57 GMT+0530 (IST) }

How to add multiple filter options in dynamo db scan method?

like image 342
Abdul Manaf Avatar asked Nov 09 '22 14:11

Abdul Manaf


1 Answers

Your FilterExpression is a list. You have to supply a string and concatenate elements using dynamos operators ( OR, AND ). For example:

FilterExpression: "x = 1 AND y = 2"

From the docs:

The syntax for FilterExpression is identical to that of ConditionExpression. In addition, FilterExpression uses the same comparators, functions, and logical operators as ConditionExpression. For more informatio

You may also need to replace keys and values to avoid error "Attribute is a reserved keyword; " See the docs for more details: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html

like image 183
Vor Avatar answered Nov 14 '22 20:11

Vor