Hoang Nguyen Ba
Hoang Nguyen Ba

Reputation: 551

Dynamodb scan with condition

I have a table in dynamodb like this:

TableName : "User",
KeySchema: [       
    { AttributeName: "id", KeyType: "HASH"}  //Partition key
],
AttributeDefinitions: [       
    { AttributeName: "id", AttributeType: "S" }
],
ProvisionedThroughput: {       
    ReadCapacityUnits: 10, 
    WriteCapacityUnits: 10
}

Now I am trying to search a user:

var params = {
    TableName: 'User',
    FilterExpression: 'contains(id, :value)',
    ExpressionAttributeValues: {
    ':value': 'ronaldo'
    }
};

dynamodb.scan(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

It's very simple, but I got a lot errors:

"message": "Expected params.ExpressionAttributeValues['value'] to be a structure"

Anyone got this ?

Upvotes: 0

Views: 2310

Answers (1)

arjun kori
arjun kori

Reputation: 1120

You can try this code: I got the same issue. Here structure meaning we should supply DataType while passing the value to It.

        var params = {
            TableName: 'User',
            FilterExpression: 'contains(id, :value)',
            ExpressionAttributeValues: {
                ':value': {
                    'S': 'ronaldo'
                }
            }
        };

        dynamodb.scan(params, function(err, data) {
            if (err) ppJson(err); // an error occurred
            else ppJson(data); // successful response
        });

Where S means String Data type.

Upvotes: 3

Related Questions