【问题标题】:Unable to use IN operator in DynamoDb Query无法在 DynamoDb 查询中使用 IN 运算符
【发布时间】:2019-04-01 12:51:41
【问题描述】:

问题是我收到错误(过滤器表达式只能包含非主键属性:主键属性:名称)。 租户是我的主分区键,名称是我的主排序键。

我需要在 dynamo db 中编写与此等效的内容: 选择 * from projects where tenant = 'testProject' and name in ('John','Dave')。

query = {
    TableName: 'projects',
    ExpressionAttributeNames: {
        '#tenant': 'tenant',
        '#name' : 'name'
    },
    ExpressionAttributeValues: {
        ":tenant": 'testProject',
        ":user1" : "John",
        ":user2" : "Dave"
    },
    KeyConditionExpression: '#tenant = :tenant',
    FilterExpression: '#name IN (:user1,:user2)'
};

【问题讨论】:

  • 这是使用的代码的副本吗?我看到您对 TableName 中的项目有反引号。这是正确的吗?
  • 我已经更正了。现在它是实际代码的副本。

标签: amazon-dynamodb dynamodb-queries


【解决方案1】:

截至我撰写本文时,您不能在关键条件表达式中使用 IN,也不能在过滤器表达式中包含关键属性。

执行您想做的事情的方法是使用BatchGetItem 请求,它允许您为多个项目指定完整的主键。

【讨论】:

    猜你喜欢
    • 2019-11-26
    • 2016-04-09
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多