node.js - 带有 NOT IN 的 DynamoDB FilterExpression

标签 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))'
  })

但是我在这里运气不佳,无法取回 userId 属性在该范围内的项目。

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

最佳答案

IN - 只有在 userId 时才能使用属性定义为 DynamoDB LIST 数据类型

IN : Checks for matching elements in a list.

AttributeValueList can contain one or more AttributeValue elements of type String, Number, or Binary. These attributes are compared against an existing attribute of an item. If any elements of the input are equal to the item attribute, the expression evaluates to true.

解决方法:

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

ExpressionAttributeValues: {
        ':to': to,
        ':from': from,
        ':userid1': "1",
        ':userid2': "2",
        ':userid3': "3"        
    },
FilterExpression: 'userId <> :userid1 and userId <> :userid2 and userId <> :userid3'

关于node.js - 带有 NOT IN 的 DynamoDB FilterExpression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41817735/

相关文章:

web-services - Node.js 参数未正确传递给路由器

javascript - 将文本聊天添加到 webRTC 音频/视频聊天

node.js - Express:使用 websocket 共享 session

javascript - socket.io 基本发出和监听器失败

amazon-web-services - 在 AWS DynamoDb 中存储时间序列

mysql - 对 2000 万条以上记录的云数据库的建议?

python - 如何查询 DynamoDB 并获取存在 "col3"而不是 0/null 的所有行 (boto3)

python - Dynamodb 增量/唯一 ID 生成

ruby-on-rails - Heroku 上的 Node.js : PostgreSQL on prod, SQLite3 on dev?

amazon-web-services - AWS 将 DynamoDB 名称导出到 Python