1

I have a Firebase Realtime Database and I want to retrieve the data from one of my table on the basis of two conditions, I have used multiple "orderBy" in my query but I am getting the following error:

ERROR => Query.orderByChild: You can't combine multiple orderBy calls.

Query =>

firebase.database().ref().child('newCoverImages').orderByChild('is_approved').equalTo(false).orderByChild('is_rejected').equalTo(false).on('value', function(snapshot) { 
      console.log(snapshot.val()); 
  });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Lokendra K
  • 21
  • 2
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For example, you could have a property: `"is_approved_is_rejected": "false_false"` and then order/filter on that property. For a longer example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Sep 28 '18 at 14:55

1 Answers1

1

This is not possible with the Realtime Database, as explained in the documentation: "You can only use one order-by method at a time.".

See https://firebase.google.com/docs/database/web/lists-of-data#sort_data


Note that you can "order by multiple fields" with Firestore, the other database service offered by Firebase. See https://firebase.google.com/docs/firestore/query-data/order-limit-data and also https://firebase.google.com/docs/firestore/query-data/queries#compound_queries which shows how to write compound queries.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • Yes, but I want to implement pagination on the basis of incoming data which is based on two conditions in a query. How can I do this thins? – Lokendra K Sep 28 '18 at 14:22
  • As I said in my answer it is simply not possible to combine multiple orderBy calls with the Realtime Database. So either you do the pagination in the front-end (can be very un-efficient and costly if you have too many records) or you change of database, e.g. use Firestore. See https://firebase.google.com/docs/firestore/query-data/query-cursors – Renaud Tarnec Sep 28 '18 at 14:27