0

I want to get all threads where status is member or owner

I know how to get for either one

reference.queryOrdered(byChild: "status").queryEqual(toValue: "owner")

Can anyone guide me how to make OR query call?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kumar
  • 1,882
  • 2
  • 27
  • 44
  • 1
    firestore is different from firebase database – Kumar Oct 11 '18 at 11:09
  • @J.Doe From article which you shared "However, after using it for some time in my own projects, there seems to be something that’s obviously missing — the ability to query with a logical OR." – Kumar Oct 11 '18 at 11:11
  • 1
    My point is that this question has been asked so many times... https://stackoverflow.com/search?q=%5Bfirebase-realtime-database%5D+or – J. Doe Oct 11 '18 at 12:00

2 Answers2

2

You can't do OR style queries in Firebase.

You can work around this by adding an additional field that is set whenever status is member or owner, and then querying on that field instead.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • 1
    Thanks. Since status have only owner or member or nil value. I am able to get my solution using reference.queryOrdered(byChild: "status").queryStarting(atValue: "member").queryEnding(atValue: "owner") – Kumar Oct 11 '18 at 12:29
0

There is no support for OR or other multi-clause queries, so you'll have to find another approach.

The simplest mapping would be to have a separate observer for each status and then merge the results client side. Contrary to what many developers think, this scales quite well since Firebase pipelines the queries/responses over a single connection.

Alternatively, you might be able to do a range query queryStarting(atValue: "member").queryEnding(atValue: "status") of there are no values in between.

Also see:

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