0

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?

Austin Berenyi
  • 1,013
  • 2
  • 13
  • 25
  • `Am I making excessive database calls having my getDocuments() inside a for loop?` -- Only you can answer that. – Robert Harvey Dec 05 '18 at 19:06
  • What you're asking for is a "logical OR" for all documents that match any one of a set of conditions. Firestore currently doesn't support this. You can only apply logical AND operations to filter documents. – Doug Stevenson Dec 05 '18 at 19:51

0 Answers0