为什么DynamoDB查询中没有“不相等”比较? [英] Why is there no **not equal** comparison in DynamoDB queries?

查看:124
本文介绍了为什么DynamoDB查询中没有“不相等”比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用辅助索引查询表 Tinpon ,该索引产生分区键类别和排序键 tinponId 。我的目标是排除具有某些tinponIds的项目。我首先想到的是做一个负比较:

keyConditionExpression = category =:category AND tinponId!=:tinponId

,但只有相等的 = 比较。然后我尝试了其他的服务方法(可悲的是不存在):

keyConditionExpression = category =:category NOT tinponId =:tinponId
keyConditionExpression = category = :category AND tinponId<>:tinponId
keyConditionExpression = category =:category AND tinponId<:tinponId AND tinponId>:tinponId

AWS指南之后,没有不相等比较。为什么这样?
还有什么方法可以查询DynamoDB,但不包括ID列表,还是唯一的选项来检索一整堆项目并稍后手动对其进行过滤?

I try to query my table Tinpon with a secondary index yielding a partition-key category and sort-key tinponId. My goal is to exclude items with certain tinponIds. My first thought would be to make a negative compare: keyConditionExpression = "category = :category AND tinponId != :tinponId" but there is only a equal = comparison. Then I tried serval other methods (with sadly do not exist): keyConditionExpression = "category = :category NOT tinponId = :tinponId" keyConditionExpression = "category = :category AND tinponId <> :tinponId" keyConditionExpression = "category = :category AND tinponId < :tinponId AND tinponId > :tinponId" Following the AWS guide there is no not equal comparisson. Why so? And is there a way to query DynamoDB excluding a list of ids or is the only option to retrieve a whole bunch of items and filter them later manually?

推荐答案

KeyConditionExpression 不允许对排序键使用不等于。但是,您可以在 FilterExpression 中使用不等于,即<>

The KeyConditionExpression doesn't allow not equals for the sort key. However, you can use the "Not Equals i.e. <>" in FilterExpression.

KeyConditionExpression : 'category = :category',    
FilterExpression : 'tinponId  <> :tinponIdVal',
ExpressionAttributeValues : {
    ':category' : 'somevalue',
    ':tinponIdVal' :  'somevalue'
}

这篇关于为什么DynamoDB查询中没有“不相等”比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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