带有 NOT IN 的 DynamoDB FilterExpression

Jos*_*son 5 node.js amazon-dynamodb

我正在尝试对 DynamoDB 查询(在 Node.JS 环境中)运行过滤器表达式,以使其中一个属性不在这些属性列表中。我这样做:

documentClient.query( {
    TableName: 'event',
    IndexName: 'OrganisationTimestamp',
    KeyConditionExpression: '#ts BETWEEN :from AND :to',
    ExpressionAttributeNames: {
      '#ts': 'Timestamp'
    },
    ExpressionAttributeValues: {
        ':to': to,
        ':from': from,
        ':ignoredUserIds': "1, 2, 3"
    },
    FilterExpression: 'not (userId in (:ignoredUserIds))'
  })
Run Code Online (Sandbox Code Playgroud)

但是,我在这里没有任何运气,并且在该范围内使用 userId 属性取回项目。

非常感谢任何帮助,谢谢!

not*_*est 6

INuserId- 仅当属性定义为 DynamoDBLIST数据类型时才能使用

IN :检查列表中的匹配元素。

AttributeValueList 可以包含一个或多个字符串、数字或二进制类型的 AttributeValue 元素。这些属性将与项目的现有属性进行比较。如果输入的任何元素等于 item 属性,则表达式的计算结果为 true。

解决方案:

如下所述更改 FilterExpression 和 ExpressionAttributeValues。它应该有效。

ExpressionAttributeValues: {
        ':to': to,
        ':from': from,
        ':userid1': "1",
        ':userid2': "2",
        ':userid3': "3"        
    },
FilterExpression: 'userId <> :userid1 and userId <> :userid2 and userId <> :userid3'
Run Code Online (Sandbox Code Playgroud)