Skip to content

Object/File Counts

Backendless version 5.x introduces new API to calculate total number of objects and files in a remote collection. In the previous version of Backendless, that number was included as a property of the returned collection. See the examples below:

Version 3.x

BackendlessDataQuery *dataQuery = [BackendlessDataQuery new];
[dataQuery setWhereClause:@"age > 21"];
MapDrivenDataStore *contactStorage = [backendless.data ofTable:@"Contact"];
[contactStorage find:dataQuery response:^(BackendlessCollection *foundObjects) {
    NSLog(@"Total number of objects matching query = %@", [foundObjects getTotalObjects]);
} error:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = "age > 21"
let contactStorage = Backendless.sharedInstance()?.data.ofTable("Contact")
contactStorage?.find(dataQuery, response: { foundObjects in
    print("Total number of objects matching query = \(foundObjects?.totalObjects ?? 0)")
}, error: { fault in
    print("Error: \(fault?.message ?? "")")
})

Version 5.x

DataQueryBuilder *queryBuilder = [DataQueryBuilder new];
[queryBuilder setWhereClauseWithWhereClause:@"age > 21"];

MapDrivenDataStore *contactStorage = [Backendless.shared.data ofTable:@"Contact"];
[contactStorage getObjectCountWithQueryBuilder:queryBuilder responseHandler:^(NSNumber *objectCount) {
    NSLog(@"Total number of objects matching query = %@", objectCount);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let queryBuilder = DataQueryBuilder()
queryBuilder.setWhereClause(whereClause: "age > 21")

let contactStorage = Backendless.shared.data.ofTable("Contact")
contactStorage.getObjectCount(queryBuilder: queryBuilder, responseHandler: { objectCount in
    print("Total number of objects matching query = \(objectCount)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

Additional resources: