带有NOT IN的DynamoDB FilterExpression [英] DynamoDB FilterExpression with NOT IN

查看:71
本文介绍了带有NOT IN的DynamoDB FilterExpression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to run a filter expression on a DynamoDB query (in a Node.JS environment), for one of the attributes not to be in a list of those attributes. I'm doing this:

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属性返回该范围内的项目。

However I'm not having any luck here, and getting items back with the userId attribute within that range.

任何帮助,谢谢!

推荐答案

IN -仅在将 userId 属性定义为DynamoDB <$ c $时使用c> LIST 数据类型

IN - can be used only if userId attribute is defined as DynamoDB LIST data type


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

IN : Checks for matching elements in a list.

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

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。

Change the FilterExpression and ExpressionAttributeValues as mentioned below. It should work.

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

这篇关于带有NOT IN的DynamoDB FilterExpression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆