0

I have an array with usernames and would like to query that again the available users in the database and get their details (age, number, address, etc.).

How to do that in Firebase using Swift? I was thinking of doing a for loop and within it I could append to array of type Users, but doesn't that mean that number of requests made to Firebase will equal to number of users in the array? That can't be the way to go...

Thanks,

ksa_coder
  • 1,393
  • 3
  • 15
  • 38
  • 1
    Firebase does not have a where clause, so there isn't a direct way to craft this query. One option is read in all of the users, a Value read, into an array and use a NSPredicate to pull out the ones we are interested in. A loop would work as well by iterating over the snapshot. This question has been asked before as well see [firebase equivalent to sql where in ()](http://stackoverflow.com/questions/29560088/firebase-equivalent-to-sql-where-in) – Jay Feb 07 '16 at 14:51
  • @Jay but won't that be bad in performance when considering a large user base and average internet connection? Thanks though for the link – ksa_coder Feb 07 '16 at 14:52
  • 1
    Depends on what a 'large user base' means. 1000 users? That's easy. 1M users, not as easy. Please read through the other posts on queries in Firebase as there are a ton of solutions. Something to consider is figuring out what relates the users you are trying to select and leverage that to get their details. – Jay Feb 07 '16 at 14:55
  • Loading additional data is a pretty cheap operation in Firebase. Since the connection is already established and *the requests are pipelined*, there is very little difference between `getUser(1); getUser(2); getUser(3);` and `getUsers(1,2,3);` Try it, you'll be surprised. – Frank van Puffelen Feb 07 '16 at 16:18

0 Answers0