I have an array of UIDs, and I want to query my root Users collection for documents containing a user object equal to each UID in my array. Right now my code looks like this:
-(void)queryFriendsOfCurrentUser{
FIRUser *user = [[FIRAuth auth] currentUser];
NSMutableArray *friendsUIDArray = [[NSMutableArray alloc] init];
for (NSString *friend in friendsUIDArray){
[[[self.db collectionWithPath:@"Users"] queryWhereField:@"uid" isEqualTo:friend] getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSDictionary *object = document.data;
[self.friendArray addObject:object];
}
}
}];
}
}
In many instances my array may contain 20+ UIDs. Am I making excessive database calls having my getDocuments()
inside a for loop?