简体   繁体   中英

Firebase AND query

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.

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());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM