如何检查dynamoDB过滤器表达式中是否不存在属性 [英] How to check whether an attribute is not present in dynamoDB filter expression
问题描述
我在dynamo DB表中引入了一个新字段InActive,现在我想获取较早处于活动状态的记录(假设所有先前的记录都处于活动状态)以及新的Active记录.
I am introducing a new field InActive in my dynamo DB table, now I want to fetch the records which were active earlier (assuming all previous records were active) along with new Active records.
我的dynamo数据库查询表达式应该是什么?
What should be my dynamo DB Query expression?
final HashMap<String, AttributeValue> activeExpressionAttrValue = new HashMap<>();
activeExpressionAttrValue.put(":in_active_false", new AttributeValue().withBOOL(false));
activeExpressionAttrValue.put(":in_active_null", new AttributeValue().withNULL(true));
dynamoDBQueryExpression.withHashKeyValues(ddbRecord.builder().primarykey(p).build())
.withFilterExpression(ddbRecord.IN_ACTIVE + " = :in_active_false OR" +
ddbRecord.IN_ACTIVE + " = :in_active_null")
.withExpressionAttributeValues(activeExpressionAttrValue);
这正确吗?
推荐答案
... ddbRecord.IN_ACTIVE + " = :in_active OR attribute_not_exists(" + ddbRecord.IN_ACTIVE + ")" ...
DynamoDb不会将隐式转换为null.为了使上面的查询正常工作,表中的数据必须包含:
DynamoDb doesn't perform implicit conversion to null. For above query to work the data in table would have to contain:
{
"some_attribute": {
"S": "some attribute string value"
},
"is_active": {
"NULL":true
}
}
但是,我怀疑表中的旧记录仅不包含"is_active"属性,而不是将其存在并设置为NULL,因此有效条件为 attribute_not_exists(is_active)
However, I suspect, that old records in table simply do not contain "is_active" attribute rather than having it present and set to NULL hence valid condition is attribute_not_exists(is_active)
这篇关于如何检查dynamoDB过滤器表达式中是否不存在属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!