0

I have firebase realtime database with data like in below imageenter image description here

user-ids key will have array of emails.How could i apply queryOrderedByChild with key and array of values in iOS

var ref = Database.database().reference().child(Constants.ACTIVES)
self.ref.queryOrdered(byChild: "user_ids").queryEqual(toValue: "krishna.vutti@gmail.com").observe(.value, with: { (snapShot) in {

})

in above query toValue is accepting single string value but in my case it would be array of emails.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Venkat
  • 347
  • 3
  • 13

1 Answers1

0

The Firebase Database API doesn't allow ordering/filtering on array contents.

If you want to be able to look up the "ACTIVES" for a specific user, you should add a node to your database where you keep the active ids for each user.

activesByUser
   uid1
     activeId1: true
     activeId2: true
   uid2
     activeId3: true

This means that you're keeping the relational information in both directions: both from active to users (which you already have) and from user to actives (with the structure I added). Keeping this information in both directions is quite common on NoSQL databases, because it makes looking up information in either direction incredibly simple

Also see my answers here:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807