I am trying to filter the data returned by a dynamodb scan operation using nodejs aws sdk but the data returned has 0 items.
Response : {"Items":[],"Count":0,"ScannedCount":15}
I have tried with both FilterExpression and ScanFilter but getting the same result.
FilterExpression:
var params = {
TableName: tableName,
FilterExpression: 'active = :active',
ExpressionAttributeValues: {
':active': {
S: '1'
}
}
};
ScanFilter:
var params = {
TableName: tableName,
ScanFilter: {
'active': {
"AttributeValueList": [{ "S": "1" }],
"ComparisonOperator": "EQ"
}
}
};
Here is the nodejs code:
dynamodb.scan(params, onScan);
function onScan(err, data) {
if (err) {
console.error('Unable to scan the table. Error JSON:', JSON.stringify(err, null, 2));
} else {
if (typeof data.LastEvaluatedKey != 'undefined') {
params.ExclusiveStartKey = data.LastEvaluatedKey;
dynamodb.scan(params, onScan);
}
if (data && data.Items)
callback(data.Items);
else
callback(null);
}
}
I checked the same filter condition in the dynamodb console and getting the expected result.
LastEvaluatedKey != 'undefined'
condition? In other words are you dealing with more than one call todynamodb.scan()
? What is the code for thecallback()
function? This isn't running in a Lambda function is it? – Mark BExpressionAttributeValues : {':active': '1'}
in the FilterExpressions – bharathp