'Why do I get empty list when doing filter?

I have a table 'test-table':

id (string) - primaryKey
type (string)

I have items like this in that table, for example:

  1. 34 AWC
  2. 56 BDE

I want to do scan table and filter by type:

I use:

async getItems(typeInput) {
    const params: ScanCommandInput = {
      TableName: "test-table",
      FilterExpression: "type in (:type)", // also tried with type = :type
      ExpressionAttributeValues: { ":type": { "S": typeInput } },
    };
    return await dynamodbdocumentclient.send(new ScanCommand(params));

}

I get as a result empty Items. Why ?



Solution 1:[1]

You appear to be using the DocumentClient, which automatically marshalls attribute values from their native JavaScript type. You do not need to wrap all values in {'S': 'xxx'}, {'N': '999'}, etc. Use ExpressionAttributeValues: { ":type": typeInput }.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ross Williams