0

我想获得许多 videoIds 的项目,而不是像这段代码中只有一个视频项目?有没有办法从索引中查询多个项目?

AWSDynamoDBObjectMapper *objectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];

queryExpression.indexName = @"getVideoItem";
queryExpression.keyConditionExpression = @"#id = :id";
queryExpression.expressionAttributeNames = @{
                                             @"#id" : @"id",
                                             };
queryExpression.expressionAttributeValues = @{
                                              @":id" : videoId,
                                              };
__weak typeof(self) weakSelf = self;

[objectMapper query:[PublicVideos class]
         expression:queryExpression
  completionHandler:^(AWSDynamoDBPaginatedOutput * _Nullable response, NSError * _Nullable error) {
      if (!error) {
          dispatch_async(dispatch_get_main_queue(), ^{
              if ([weakSelf.delegate respondsToSelector:@selector(ServerConnectionHandlerVideoListRecevied:)]) {
                  [weakSelf.delegate ServerConnectionHandlerVideoListRecevied:response.items];
              }
          });
      }
  }];
4

1 回答 1

1

您的表的架构是什么样的?您是否为您的表启用了哈希键和范围键?如果您没有任何范围键,则每个散列键只有 1 个条目,并且您的查询将只返回一行。

如果您同时拥有哈希键和范围键,则可以通过以下方式进行查询:

AWSDynamoDBObjectMapper *objectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];
queryExpression.indexName = @"Artist-Album-index";
queryExpression.keyConditionExpression = @"#artist = :artist AND #album < :album";
queryExpression.expressionAttributeNames = @{
                                                 @"#artist" : @"Artist",
                                                 @"#album" : @"Album",
                                                 };
queryExpression.expressionAttributeValues = @{
                                                  @":artist" : @"valuetosearch",
                                                  @":album" : @"valuetosearch",
                                                  };
[objectMapper query:[Song class]
             expression:queryExpression
      completionHandler:^(AWSDynamoDBPaginatedOutput * _Nullable response, NSError * _Nullable error) {
          dispatch_async(dispatch_get_main_queue(), ^{
              // handle response
          });
      }];

在上面的代码片段中,它尝试为匹配“<”条件的艺术家查找所有专辑

于 2016-10-06T20:50:26.297 回答