1

I'm wanting to use Firebase to select calendar events which have either already started but haven't ended, or which start within the next 6 months.

In pseudo-SQL, what I'm wanting is:

WHERE `start` < {6 months from now} AND `end` > {now}

The problem is, I know how to get one of these use cases, but not both:

firebase.orderByChild('start').endAt(+new Date() + 15724800000)
firebase.orderByChild('end').startAt(+new Date())

If I attempt to combine the two, I get the following error:

Uncaught Error: Query.orderByChild: You can't combine multiple orderBy calls.

I'm not wanting to execute two queries in order to filter the list down. There will only likely be a couple of results which match the query I'm wanting, but there may be millions of results which match either of the queries by themselves.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • Closely related: [Query based on multiple where clauses in firebase](http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase). Did you already look if you can combine the `start` and `end` properties as described there? – Frank van Puffelen Apr 27 '16 at 16:04
  • @FrankvanPuffelen the problem is that the events I'm trying to pull may have already started, so I can't use `.startAt(start)` because that would ignore anything which has already begun. I'm not wanting to do this with two queries because both of those queries may return a lot of data. Returning anything that starts in the next 6 months (or has already started) would require pulling every event whose start date has already passed. – James Donnelly Apr 29 '16 at 08:08

1 Answers1

0

https://www.firebase.com/blog/2013-10-01-queries-part-one.html#between

firebase.orderByChild('start')
.startAt(startTime)
.endAt(endTime)
.once('value', function(snap) {
   console.log('messages in range', snap.val());
});
Suleiman
  • 1,003
  • 2
  • 15
  • 29
  • I'm not looking for messages in a specific range. If an event has already started but hasn't ended, calling `.startAt(startTime)` will filter it out. This isn't what I want. – James Donnelly Apr 29 '16 at 08:05