2017-03-05 5 views
0

私はDynamoDBに移行します。 mySQLでは、私はdynamoDBクエリ:SELECT * FROM mytable WHERE userId IN myList

SELECT * FROM mytable WHERE userId IN myList 

DynamoDBでどうすれば実現できますか?あなたは上記のSQLクエリと同じ結果を達成するためにScan操作にfilter expressionを使用することができます

おかげ

+0

Useridは通常の属性ですか、またはdynamodbテーブルのハッシュまたはソートキーとして定義されていますか? – notionquest

答えて

0

。たとえば、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); 
関連する問題