1

This code returns the whole set of items, where I need only the count of it. Is it possible to get only the count of the items for this index?

    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];
              }
          });
      }
  }];

Like here for example:

aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT"
vatti
  • 463
  • 7
  • 16
  • Not familiar with objective-c or the respective sdk but it should be possible to set the "Select" parameter to "COUNT", as in your CLI example, somehow as well. Here's a Java example https://stackoverflow.com/a/27327486/3484824 – Can Rau Jul 30 '20 at 01:21

1 Answers1

2

You can use the DescribeTable API: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html

There is an "itemCount" attribute. Keep in mind that this is not live data (updated every 6 hours). So if you're looking for live data, you would need to do a full table scan. However, full table scans are not recommended because they can be expensive depending on the size of your table.

Lisa M Shon
  • 502
  • 4
  • 8
  • 1
    Does the itemcount work with query? Because, I dont want the whole table count but only the number of items that has that videoID. – vatti Oct 04 '16 at 15:54
  • 1
    According to: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html You can use the **Count** parameter to get the total number of items that match the filter/condition for scan/query – Lisa M Shon Oct 04 '16 at 20:36
  • Yes, but it returns all the items and there you have the count parameter, as well. I need only the count parameter to be returned, not the items. Sorry, if I am missing something. – vatti Oct 05 '16 at 10:41