代码之家  ›  专栏  ›  技术社区  ›  fewfew

为什么在进行筛选时会得到空列表?

  •  0
  • fewfew  · 技术社区  · 2 年前

    我有一个表“测试表”:

    id (string) - primaryKey
    type (string)
    

    我在该表中有类似的项目,例如:

    1. 34 AWC
    2. 56溴二苯醚

    我想按类型扫描表和筛选:

    我使用:

    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));
    
    }
    

    结果我得到了空的项目。为什么?

    0 回复  |  直到 2 年前
        1
  •  0
  •   Ross Williams    2 年前

    您似乎正在使用DocumentClient,它会自动封送来自其本机JavaScript类型的属性值。您不需要将所有值包装在{'S':'xxx'}、{'N':'999'}等中。请使用 ExpressionAttributeValues: { ":type": typeInput }