Amazon dynamodb fiter expression return error

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

time stamp | userid | text

101 | manaf | haaaai

102 | manaf | Hello

I need to get data between two res limits.

this is my js code.

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 an 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 several filter parameters to dynamo-db-scan method?

+5
source share
1 answer

Your FilterExpression is a list. You must specify a string and combine the elements using the dynamos (OR, AND) operators. For instance:

 FilterExpression: "x = 1 AND y = 2" 

From the docs:

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

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

+1
source

All Articles