0

I'm writing an Android app using Firebase. As I already understood, Firebase supports only queries for one property, so order... calls cannot be chained. The solution suggested in most of the cases is either a property combination in each item or creating a secondary index (for example, see here).

However, this works mostly in case of equalTo() requests. My case is the following (and can be very common, I believe):

|- events
|    |
|    |- event1
|    |   |
|    |   |- name
|    |   |- startDate
|    |   |- endDate
|    |
|    |- event2
|    |   |
|    |   |- name
|    |   |- startDate
|    |   |- endDate
|    |

Now I want a date range overlapping query - give me all the events next month (event might span over several months).

Is this somehow possible with Firebase without client side processing or filtering? Any kind of tricks/combinations/indices that I can create in my DB?

I want to use the query results with FirebaseUI adapters, which don't support filtering.

Community
  • 1
  • 1
frangulyan
  • 3,580
  • 4
  • 36
  • 64

1 Answers1

0

Easy way for you

https://github.com/davideast/Querybase

Use this

 const databaseRef = firebase.database.ref().child('events');
 const querybaseRef = querybase.query(databaseRef);

 querybaseRef.where('startDate').lessThan(endDate);
 querybaseRef.where('endDate').greaterThan(startDate);
Heisenberg
  • 313
  • 1
  • 2
  • 17
  • 2
    Then I have 2 sets of results which I have to manually intersect, right? The key part in my question was **"without client side processing or filtering"** – frangulyan Oct 24 '16 at 18:38