dynamoDB查询:SELECT * FROM mytable WHERE userId IN myList

时间:2017-03-05 21:14:50

标签: amazon-dynamodb

我将mySQL迁移到DynamoDB。在mySQL中,我有

SELECT * FROM mytable WHERE userId IN myList

如何在DynamoDB中实现它?

由于

1 个答案:

答案 0 :(得分:0)

您可以在filter expression操作上使用Scan来获得与上述SQL查询相同的结果。例如,如果您在Java中使用Document SDK,则可以编写以下内容:

final Table table = new Table(AmazonDynamoDBClient.builder().withRegion(Regions.US_EAST_1).build(), "mytable");
//convert the Iterable<Item> returned by table.scan() to a stream of Items
StreamSupport.stream(
        // list however many items you need to test after IN
        table.scan(new ScanSpec().withFilterExpression("userId IN :u1, :u2")
                //define the values of the set of usernames you are testing in the list avove
                .withValueMap(ImmutableMap.of(":u1", "robert", ":u2", "daniel"))).spliterator(), false)
        //do useful stuff with the result set
        .map(Item::toJSONPretty)
        .forEach(System.out::println);