There is this list of Books in the Firebase Realtime Database:
[
  {
    title: "Don't Make Me Think",
    upvotes: 110
  },
  {
    title: "The Mythical Man Month",
    upvotes: 111
  },
  {
    title: "Code Complete 2",
    upvotes: 112
  }
]
By default, the query below returns this list in ASC order:
firebase.database().ref('books').orderByChild('upvotes')
How can I query and order them by upvotes DESC instead?
Unfortunately firebase doesn't allow returning by descending order. I have generally just reversed the order of the results returned client side.
If your data query is too large to sort client side you can do
firebase.database().ref('books').orderByChild('ups').limitToLast(2)
and then invert the results from there. Documentation can be seen here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With