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"
itemcount是否適用於查詢?因爲,我不希望整個表的數量,但只有具有該videoID項目的數量。 – vatti
根據:http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html 您可以使用** Count **參數來獲取與過濾條件匹配的項目總數用於掃描/查詢 –
是的,但它會返回所有項目,並且您還有count參數。我只需要返回count參數,而不是項目。對不起,如果我錯過了一些東西。 – vatti