0

此代码返回整套物品,我只需要计数它的数量。是否有可能只获得这个索引的项目数?DynamoDB获取物品计数

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

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

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

+1

itemcount是否适用于查询?因为,我不希望整个表的数量,但只有具有该videoID项目的数量。 – vatti

+0

根据:http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html 您可以使用** Count **参数来获取与过滤条件匹配的项目总数用于扫描/查询 –

+0

是的,但它会返回所有项目,并且您还有count参数。我只需要返回count参数,而不是项目。对不起,如果我错过了一些东西。 – vatti