本文介绍了将dynamoDB写为“ OR”。条件查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用布尔值或类似SQL
之类的条件查询dynamodb表。 给我所有其中attribute1 = no或attribute2 = no

I want to query the dynamodb table with boolean or condition like SQLe.g. Get me all the items where attribute1 = "no" or attribute2="no"

我尝试使用 scanRequest.withScanFilter ,但所有条件都是通过布尔ANDing执行的。我该怎么做布尔ORing ??

I tried with scanRequest.withScanFilter but all the conditions are performed by doing boolean ANDing. How do I do boolean ORing.?

推荐答案

您可以将ScanRequest的ConditionalOperator设置为 OR。默认值为 AND

You can set ConditionalOperator of your ScanRequest to "OR". The default value is "AND"

ScanRequest scanRequest = new ScanRequest("tableName");
scanRequest.setConditionalOperator(ConditionalOperator.OR);

Map<String, Condition> scanFilter = new HashMap<String, Condition>();
scanFilter.put("attribute1", new Condition().withAttributeValueList(new AttributeValue("no")).withComparisonOperator(ComparisonOperator.EQ));
scanFilter.put("attribute2", new Condition().withAttributeValueList(new AttributeValue("no")).withComparisonOperator(ComparisonOperator.EQ));

scanRequest.setScanFilter(scanFilter);
ScanResult scanResult = dynamo.scan(scanRequest);

for(Map<String, AttributeValue> item : scanResult.getItems()) {
    System.out.println(item);
}

这篇关于将dynamoDB写为“ OR”。条件查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:06