3

I want to query my data with a where clause with an or. Below is my current code.

let friendQuery = friendMapRef.queryEqualToValue(loggedUser.UserId, childKey: "sender_id")

And its retrieving fine, but i want to match if any friend map has sender_id value as my userid or receiver_id as my userid value. How can i achieve this?

Mahesh Agrawal
  • 3,348
  • 20
  • 34
  • Firebase Database queries can only query on a single property. You may be able to combine the values you want to query on into a single property. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Nov 23 '16 at 04:01
  • by looking at the link its clear that i can combine 2 conditions and thats an AND clause. i want to check OR. can you point me in any other post. because i tried so many stack posts but no luck. – Mahesh Agrawal Nov 23 '16 at 05:12
  • For an `OR` you'll have to change your data structure to create a separate list of the values you're searching for and then for each of those the corresponding keys of the items that match it. If you'd like a concrete example, edit your question to include a minimal snippet of the actual JSON that you use. – Frank van Puffelen Nov 23 '16 at 05:28
  • i got your point. finally i have to change my data structure. thank you for clearing the doubt. – Mahesh Agrawal Nov 23 '16 at 07:03
  • actually what i did is, i retrieved twice with both key and merged both the list and sorted by date time. this is quickest and i don't have to change my database also. – Mahesh Agrawal Nov 23 '16 at 07:06
  • 2
    Good to hear. If you can post that as an answer (including a minimal code snippet), it might be useful to future visitors. – Frank van Puffelen Nov 23 '16 at 16:05

0 Answers0