1

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

    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"
4

1 回答 1

2

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

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

于 2016-10-03T20:27:10.673 回答