我想用布尔值或类似SQL的条件查询dynamodb表
例如Get me all the items where attribute1 = "no" or attribute2="no"
我尝试使用scanRequest.withScanFilter
,但是所有条件都是通过布尔ANDing执行的。我该如何进行布尔ORing。
最佳答案
您可以将ScanRequest的ConditionalOperator设置为“ OR”。默认值为“ AND”
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
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);
}
关于amazon-dynamodb - 编写dynamoDB“或”条件查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24275243/