问题描述
我尝试使用生成分区键 category 和排序键 tinponId 的二级索引查询我的表 Tinpon.我的目标是排除具有某些 tinponIds 的项目.我的第一个想法是进行否定比较:但只有相等的 = 比较.然后我尝试了其他方法(遗憾的是不存在):遵循 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
中使用 "Not Equals i.e. <>".
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 查询中没有**不等于**比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!