0

I'm new on Swift and Firebase and I'm trying to build a dating app. I need to select the users randomly from Firebase by gender, age and others criteria. Please, how should be the best way to do that?

Ivan
  • 34,531
  • 8
  • 55
  • 100
  • I suggest you use Firebase Cloud Functions instead of directly using Realtime Database. https://firebase.google.com/docs/functions/ – Anton Belousov May 26 '18 at 10:39
  • 1
    @AntonBelousov I believe what the OP is asking for goes beyond what a cloud function can really do. In this case it's a complex query based on multiple fields and random number generation. I would love to see that in action though - perhaps you can provide an answer that contains an example of that cloud function? – Jay May 26 '18 at 13:20
  • 1
    The bad news is that querying on multiple fields is not Firebase's strong suit. While it can be done, it needs to be approached differently. The simplest solution is to load users and filter in code. That works fine for a few thousand, but doesn't scale well beyond that. Second option is to filter using [Compound Values](https://stackoverflow.com/questions/49531960/count-unseen-messages-with-firebase-in-swift/49539137#49539137) and [this](https://stackoverflow.com/questions/45433558/how-to-apply-multiple-filter-in-firebase-query-in-swift/45469440#45469440). – Jay May 26 '18 at 13:32
  • 1
    It wasn't specified if you are working with Firebase Database or Cloud Firestore but if you've not looked at [Firestore](https://firebase.google.com/docs/firestore/), it would be better suited for this task because *queries can include multiple, chained filters and combine filtering and sorting* – Jay May 26 '18 at 13:35
  • Thank you everyone for your comments. Yes, a friend already gave me a tip to try use the Firebase Functions, but once inside a function, how should I do a random selection in Firebase and return the user? Anyone have an example? – Evaristo Broullon May 28 '18 at 08:48

0 Answers0