DynamoDB获取项目数

时间:2016-10-03 16:27:44

标签: ios objective-c amazon-web-services amazon-dynamodb aws-sdk-ios

此代码返回整个项目集,其中我只需要计数。是否可以只获得该索引的项目数?

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

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

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

比如这里:

aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT"

1 个答案:

答案 0 :(得分:1)

您可以使用DescribeTable API:http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html

有一个&#34; itemCount&#34;属性。请记住,这不是实时数据(每6小时更新一次)。因此,如果您正在寻找实时数据,则需要进行全表扫描。但是,不建议使用全表扫描,因为根据表的大小,它们可能很昂贵。