[英]How to query(getItems) for two conditions (non-existent + some value) on single attribute in DynamoDB?
I'm trying to query(getItems) on DynamoDB table to find all items where the InitiateMQFlag = 0 or the 'InitiateMQFlag' attribute is not yet set.我正在尝试在 DynamoDB 表上查询(getItems)以查找尚未设置 InitiateMQFlag = 0 或“InitiateMQFlag”属性的所有项目。 A global secondary index called BLEAdvertisement-InitiateMQFlag-index exists on the table which includes the InitiateMQFlag field.
包含 InitiateMQFlag 字段的表上存在一个名为 BLEAdvertisement-InitiateMQFlag-index 的全局二级索引。 I had used FilterExpression: "attribute_not_exists(InitiateMQFlag)" but it throws me errors.
我曾使用过 FilterExpression: "attribute_not_exists(InitiateMQFlag)" 但它会引发错误。
var params = {
TableName: device_table,
IndexName: "BLEAdvertisement-InitiateMQFlag-index",
KeyConditionExpression: "BLEAdvertisement = :BLEAdvertisement AND InitiateMQFlag = :InitiateMQFlag",
ExpressionAttributeValues: {
':BLEAdvertisement': BLEAdvertisements[i],
':InitiateMQFlag' : InitiateMQFlagValue
},
FilterExpression: "attribute_not_exists(InitiateMQFlag)"
};
Result:结果:
code:"ValidationException"
message:"Filter Expression can only contain non-primary key attributes: Primary key attribute: InitiateMQFlag"
name:"ValidationException"
requestId:"OVIAPBSCAAU42OI41LQUSGIU7JVV4KQNSO5AEMVJF66Q9ASUAAJG"
retryable:false
retryDelay:3.1105465830200685
statusCode:400
If there is another way to get the non-existent attribute with another query on single attribute, it will also help a lot.如果有另一种方法可以通过对单个属性的另一个查询来获取不存在的属性,它也会有很大帮助。
A FilterExpression
is used to relatively-inefficiently filter out results after already reading them from the partition - you'll be paying for the read before the filtering happens. FilterExpression
用于在已经从分区中读取结果之后相对低效地过滤掉结果 - 您将在过滤发生之前为读取付费。 DynamoDB is refusing to allow you to filter on a primary key (partition key or sort key) to hint you that there is a more efficient way to do this: You should use a KeyConditionExpression
instead. DynamoDB 拒绝允许您过滤主键(分区键或排序键)以提示您有更有效的方法来执行此操作:您应该改用
KeyConditionExpression
。
And, in your case, you are indeed doing a KeyConditionExpression
on the key column InitiateMQFlag.而且,在您的情况下,您确实在键列 InitiateMQFlag 上执行
KeyConditionExpression
。 So beyond the fact that it's not allowed to filter on this column, why would you even want to?因此,除了不允许在此列上进行过滤这一事实之外,您为什么还要这样做呢? Given
KeyConditionExpression
already limits the query only to items where InitiateMQFlag =:InitiateMQFlag - how can it ever match the attribute_not_exists(InitiateMQFlag) filter?鉴于
KeyConditionExpression
已经将查询限制为仅对 InitiateMQFlag =:InitiateMQFlag 的项目 - 它如何匹配 attribute_not_exists(InitiateMQFlag) 过滤器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.