1

Here's a link to:

My Database

So, my question is, I want to filter the articles by their type (i.e. "news," or "voice"), and then order those articles by the date that they were published (YYYY-MM-DD). So far, I have written the code:

var news = firebase.database().ref().child('articles').orderByChild('type').startAt('news').endAt('news');
news.orderByChild('date').on('value', function(snapshot) {
  console.log(snapshot.val());
});

(Sorry for the snippet, the equals sign was messing with the formatting)

The console then gives me the error:

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

Is it possible to do what I'm trying to do, or do I have to find something else?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • you cannot multi ordering in firebase, one choice is to do the second ordering in the client – mohamad rabee Aug 19 '17 at 16:30
  • As the error message says you can only have one `orderBy` per query. If you want to order/filter on multiple values, you may be able to combine the values into a single property and order on that. E.g. `"type_date": "news_2017-08-19"`. For more, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Aug 19 '17 at 16:40
  • Thank you! I searched for something like that question for an entire day :) – Sam Uyemura Aug 19 '17 at 18:14

0 Answers0