Home > Net >  Firestore query passing in an array of String - Firestore - Swift
Firestore query passing in an array of String - Firestore - Swift

Time:10-18

I have an array of UIDs (String) and I want to perform a query using Firestore where I get all the documents in which the field "uid" is equal to any of the ones in the array provided.

Till now I tried doing:

ref.whereField("uid", in: uidArray)

But this doesn't work and gives me an error because the maximum number of elements in the array must be 10 and it surely surpasses that limit.

My question is: how can I achieve the same result with a workaround using Firestore?

Whenever I try to implement a query using this DB it seems it's built for making developers' lives harder.

CodePudding user response:

Yes, according to the docs, the maximum number of elements in the array is 10. To be able to get over this limitation, you should perform successive calls. For example, if you need to check a field against 35 values, then you should perform 4 queries. Three queries with the 10 elements and the fourth with 5 elements. Lastly, you should combine the result on the client.

  • Related