我正在尝试对 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/